** Clearing Stata memory
capture log close
clear all
set more off, perm
set seed 1234

**********************************************************************************************************************************************************
*************************************************************** Importing / Checking *********************************************************************	
**********************************************************************************************************************************************************

******************************************
************ Socioeconomic ***************
******************************************

/* Files QSEPR */

*********************************
**********  ALL YEARS  **********
*********************************

forvalues i = 0(1)8 {

insheet using "Original data/V200`i'_QSEPR.txt"

/* VARIABLE NAME */

rename inscri2	  studentno
rename inscri	  inscription
rename opc1       career_choice                          
rename paais      aa_policy                          
rename isentos    regist_fee                        
rename aprovf2    pass_st1                          
rename matr       enroll                          
rename curpas     career_enroll                          
rename idade	  age                                
rename sexo       sex                          
rename raca       race                          
rename ensfund    sch_fund                          
rename ensmed     sch_med                          
rename tipomed    type_med                          
rename fezcpv     prep_course                          
rename tipocpv    type_prep                          
rename opcunicamp reason_unicamp                          
rename motcarr    reason_career                          
rename renda	  income_cat                                
rename rbruta     income                          
rename qtsvivem   member_live                          
rename catpai     profes_father                          
rename catmae     profes_mother                          
rename instrpai   educ_father                          
rename instrmae   educ_mother                          
rename trabalha   working                          
rename lejornal   read_newspaper         

/* VARIABLE LABEL */

gen year=200`i'

/* variable: aa_policy */                          
replace aa_policy=0 if aa_policy==-1                          
label define aa_policy 0 "no" 1 "30 points" 2 "40 points" 3 "not-mentioned" 
label values aa_policy aa_policy                         

/* create a label for yes and no questions */
label define yn 1 yes 0 no

/* variable: regist_fee */                         
label values regist_fee yn
                      
/* variable: pass_st1 */
label variable pass_st1 "Original name: aprovf2. It refers to if the the student get through the stage 2 or not"                          
label values pass_st1 yn
                         
/* variable: enroll */                          
label values enroll yn                         

/* variable: age */
replace age=. if age==0
label define age 1 "less than 16 years old" 2 "16 years old" 3 "17 years old" 4 "18 years old" 5 "19 years old" 6 "20 years old" 7 "21-23 years old" 8 "24-29 years old" 9 "more than 29 years old"
label values age age

/* variable: sex */
replace sex=. if sex==0
label define sex 1 m 2 f
label values sex sex

/* variable: race */
replace race=. if race==0
replace race=. if race==-1
label define race 1 white 2 black 3 mulatto 4 asian 5 native
label values race race

/* create a label for sch_fund and sch_med */
label define sch 1 onlypriv 2 onlypub 3 pubpriv 4 privpub 5 half 6 none

/* variable: sch_fund */
replace sch_fund=. if sch_fund==0
label values sch_fund sch

/* variable: sch_med */
replace sch_med=. if sch_med==0
label values sch_med sch

/* variable: type_med */
replace type_med=. if type_med==0
/* recode 2004-2008 to be compatible with previous years (no regularprep) */
recode type_med (4=3) (5=4) (6=5) (7=6) if year==2004 | year==2005 | year==2006 | year==2007 | year==2008
label define type_med 1 technical 2 "teacher training" 3 regular 4 accelerated  5 abroad 6 other
label values type_med type_med

/* variable: prep_course */
replace prep_course=. if prep_course==0
replace prep_course=0 if prep_course==2
label values prep_course yn

/* variable: type_prep */
replace type_prep=. if type_prep==0
replace type_prep=. if type_prep==-1
label define type_prep 1 commercial 2 community 
label values type_prep type_prep

/* variable: reason_unicamp */
replace reason_unicamp=. if reason_unicamp==0
label define reason_unicamp 1 "best for the course"  2 "free" 3 "close to residence" 4 "friends" 5 "reputation" 6 "rich cultural university life" 7 "access to scientific career" 8 "other"
label values reason_unicamp reason_unicamp

/* variable: reason_career */
replace reason_career=. if reason_career==0
label define reason_career 1 "personal ability"  2 "social status" 3 "jobmarket" 4 "contribution to society" 5 "low competition for access" 6 "personal realization" 7 "other"
label values reason_career reason_career

/* variable: income_cat */
replace income_cat=. if income_cat==0
label define income_cat 1 "up to 1 min wage"  2 "1-3 min wage" 3 "3-5 min wage" 4 "5-10 min wage" 5 "10-15 min wage" 6 "15-20 min wage" 7 "20-30 min wage" 8 "30-40 min wage" 9 "more than 40 min wage"
label values income_cat income_cat

/* variable: income */
capture noisily destring income, replace force
replace income=. if income==-1
replace income=. if income== 0

label define member_num 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6+"

/* variable: member_live */
replace member_live=. if member_live==0
label values member_live member_num

label define profes 1 "high politics, business, owner large company" 2 "self-employed, manager, owner medium company" 3 "supervision or inspection of non manual activities, owner small company" 4 "non-manual repetitive occupation" 5 "supervision manual occupation" 6 "specialized manual occupation" 7 "non-specialized manual occupation" 8 "house husband/wife" 9 "other"

/* variable: profes_father */
replace profes_father=. if profes_father==0
replace profes_father=9 if profes_father==10
label values profes_father profes

/* variable: profes_mother */
replace profes_mother=. if profes_mother==0
replace profes_mother=9 if profes_mother==10
label values profes_mother profes

label define educ 1 "no school" 2 "primary incomplete" 3 "primary complete" 4 "low secondary incomplete" 5 "low secondary complete" 6 "high secondary incomplete" 7 "high secondary complete" 8 "university incomplete" 9 "university complete"

/* variable: educ_father */
/* recode to eliminate post university to be compatible with the years before 2005 */
recode educ_father (10=9) (11=9) if year==2005 | year==2006 | year==2007 | year==2008
replace educ_father=. if educ_father==0
label values educ_father educ

/* variable: educ_mother */
recode educ_mother (10=9) (11=9) if year==2005 | year==2006 | year==2007 | year==2008
replace educ_mother=. if educ_mother==0
label values educ_mother educ

/* variable: working */
replace working=. if working==0
label define working 1 "no" 2 "yes, occasionally" 3 "yes, half time (up to 20h)" 4 "yes, semi integral (21h-32h)" 5 "yes, integral (more than 32h)"
label values working working

/* variable: read_newspaper */
replace read_newspaper=. if read_newspaper==0
label define read_newspaper 1 "no" 2 "yes, occasionally" 3 "yes, on sundays" 4 "yes, daily"
label values read_newspaper read_newspaper

rename career_choice	career_choice_pr                         
rename age       		age_pr                         
rename sex    			sex_pr                      
rename race    			race_pr                      
rename sch_fund 		sch_fund_pr                         
rename sch_med  		sch_med_pr                        
rename type_med  		type_med_pr                        
rename prep_course 		prep_course_pr                         
rename type_prep   		type_prep_pr                       
rename reason_unicamp  	reason_unicamp_pr                        
rename reason_career 	reason_career_pr                         
rename income_cat  		income_cat_pr                              
rename income 			income_pr                         
rename member_live  	member_live_pr                        
rename profes_father 	profes_father_pr                         
rename profes_mother  	profes_mother_pr                        
rename educ_father 		educ_father_pr                         
rename educ_mother 		educ_mother_pr                         
rename working   		working_pr                       
rename read_newspaper   read_newspaper_pr      

sort inscription

save "Work data/QSEPR/V200`i'_QSEPR.dta", replace
clear
}

/* Files QSETT */

/* 2000 */

clear
insheet using "Original data/V2000_QSETT.txt"

describe

*********************************
*							    *
* VARIABLE: LABELS AND ANALYSIS *
*								*
*********************************

rename inscri inscription
rename curso career_choice
drop p44

gen year=2000
order year, after(inscription)

/* variable: sex */
rename p1 sex
replace sex=. if sex==0
label define sex 1 m 2 f
label values sex sex
inspect sex
describe sex

/* variable: age */
rename p2 age
replace age=. if age==0
label define age 1 "less than 16 years old" 2 "16 years old" 3 "17 years old" 4 "18 years old" 5 "19 years old" 6 "20 years old" 7 "21-23 years old" 8 "24-29 years old" 9 "more than 29 years old"
label values age age
inspect age
describe age

/* variable: marstat */
rename p3 marstat
replace marstat=. if marstat==0
label define marstat 1 single 2 married 3 widowed 4 divorced 5 other
label values marstat marstat
inspect marstat
describe marstat

/* variable: resid_fam_or */
/* this variable is not compatible with other years */
gen resid_fam_or=p4
replace resid_fam_or=. if resid_fam_or==0
label define resid_fam_or 1 "sao paulo metropolitan region" 2 "sao paulo inland" 3 "sao paulo coast" 4 "other state capital" 5 "other state inland" 6 "other state coast"
label values resid_fam_or resid_fam_or
inspect resid_fam_or
describe resid_fam_or

/* variable: resid_fam */
/* group to be compatible with 2003 recode */
rename p4 resid_famw
recode resid_famw (3=2) (4=3) (5=3) (6=3), gen(resid_fam)
replace resid_fam=. if resid_fam==0
label define resid_fam 1 resid_fam
label values resid_fam resid_fam
drop resid_famw
inspect resid_fam
describe resid_fam

/* variable: other_vest */
rename p5 other_vest
replace other_vest=. if other_vest==0
label define other_vest 1 "only unicamp" 2 "unicamp and fuvest" 3 "unicamp and vunesp" 4 "unicamp, fuvest and vunesp" 5 "unicamp and other private" 6 "unicamp and other public" 7 "unicamp and other public and private" 8 "other"
label values other_vest other_vest
inspect other_vest
describe other_vest

/* create a label for sch_fund and sch_med */
label define sch 1 onlypriv 2 onlypub 3 pubpriv 4 privpub 5 half 6 none

/* variable: sch_fund */
rename p6 sch_fund
replace sch_fund=. if sch_fund==0
label values sch_fund sch
inspect sch_fund
describe sch_fund

/* variable: sch_med */
rename p7 sch_med
replace sch_med=. if sch_med==0
label values sch_med sch
inspect sch_med
describe sch_med

/* variable: type_med */
rename p8 type_med
replace type_med=. if type_med==0
label define type_med 1 technical 2 "teacher training" 3 regular 4 accelerated  5 abroad 6 other
label values type_med type_med
inspect type_med
describe type_med

/* variable: period_med */
rename p9 period_med
replace period_med=. if period_med==0
label define period_med 1 morning 2 afternoon 3 evening 4 morneven 5 evenmorn 6 wholeday 7 other
label values period_med period_med
inspect period_med
describe period_med

/* variable: repeat_med */
rename p10 repeat_med
replace repeat_med=. if repeat_med==0
replace repeat_med=. if repeat_med>=6 & repeat_med<.
label define repeat_med 1 "no" 2 "yes, once" 3 "yes, twice" 4 "yes, 3 times" 5 "yes, more than 3 times"
label values repeat_med repeat_med
inspect repeat_med
describe repeat_med

/* create a label for yes and no questions */
label define yn 2 "not-appl" 1 yes 0 no
* label define yn 1 yes 2 no

/* variable: prep_course */
rename p11 prep_course
replace prep_course=. if prep_course==0
replace prep_course=0 if prep_course==2
label values prep_course yn
inspect prep_course
describe prep_course

/* variable: reason_prep */
rename p12 reason_prep
replace reason_prep=. if reason_prep==0
replace reason_prep=. if reason_prep==9
label define reason_prep 1 "school does not prepare well" 2 "reinforce school" 3 "stop study long time ago" 4 "integrated at school" 5 "scholarship" 6 "other"
label values reason_prep reason_prep
inspect reason_prep
describe reason_prep

/* variable: durat_prep */
rename p13 durat_prep
replace durat_prep=. if durat_prep==0
label define durat_prep 1 "< 6 months" 2 "6 months-1 year" 3 "up to 1.5year" 4 "up to 2 years" 5 "more than 2 years"
label values durat_prep durat_prep
inspect durat_prep
describe durat_prep

/* variable: reason_noprep */
rename p14 reason_noprep
replace reason_noprep=. if reason_noprep==0
label define reason_noprep 1 "school prepares well" 2 "economic difficulties" 3 "coincide with work time" 4 "thought could study alone" 5 "no prep close to home" 6 "school offers integrated" 7 "other"
label values reason_noprep reason_noprep
inspect reason_noprep
describe reason_noprep

/* variable: vest_before */
rename p15 vest_before
replace vest_before=. if vest_before==0
label define vest_before 1 "no" 2 "yes, one" 3 "yes, twice" 4 "yes, three" 5 "yes, more than three"
label values vest_before vest_before
inspect vest_before
describe vest_before

/* variable: vest_beforwhere */
rename p16 vest_beforwhere
replace vest_beforwhere=. if vest_beforwhere==0
label define vest_beforwhere 1 "only unicamp" 2 "unicamp and other public" 3 "only other public" 4 "unicamp and private" 5 "only private" 6 "unicamp and other public and private" 7 "only other public and private"
label values vest_beforwhere vest_beforwhere
inspect vest_beforwhere
describe vest_beforwhere

/* variable: other_univ */
rename p17 other_univ
replace other_univ=. if other_univ==0
replace other_univ=0 if other_univ==2
label values other_univ yn
inspect other_univ
describe other_univ

/* variable: other_univreas */
rename p18 other_univreas
replace other_univreas=. if other_univreas==0
label define other_univreas 1 "dropped out" 2 "over" 3 "will give up" 4 "do both" 5 "keep other, only experience vestibular" 6 "other"
label values other_univreas other_univreas
inspect  other_univreas
describe other_univreas

/* variable: other_univinst */
rename p19 other_univinst
replace other_univinst=. if other_univinst==0
label define other_univinst 1 "usp" 2 "unicamp" 3 "unesp" 4 "puc-sp" 5 "puc-campinas" 6 "federal or state university" 7 "private institution" 8 "other"
label values other_univinst other_univinst
inspect  other_univinst
describe other_univinst

/* variable: other_univdropreas */
rename p20 other_univdropreas
replace other_univdropreas=. if other_univdropreas==0
label define other_univdropreas 1 "not preferred career" 2 "not preferred university" 3 "disappointed with course" 4 "change in professional option" 5 "financial reasons" 6 "start working" 7 "not able to follow the course" 8 "other reasons"
label values other_univdropreas other_univdropreas
inspect  other_univdropreas
describe other_univdropreas

/* variable: reason_unicamp */
rename p21 reason_unicamp
replace reason_unicamp=. if reason_unicamp==0
label define reason_unicamp 1 "best for the course"  2 "free" 3 "close to residence" 4 "friends" 5 "reputation" 6 "rich cultural university life" 7 "access to scientific career" 8 "other"
label values reason_unicamp reason_unicamp
inspect reason_unicamp
describe reason_unicamp

/* variable: reason_career */
rename p22 reason_career
replace reason_career=. if reason_career==0
label define reason_career 1 "personal ability"  2 "social status" 3 "jobmarket" 4 "contribution to society" 5 "low competition for access" 6 "personal realization" 7 "other"
label values reason_career reason_career
inspect reason_career
describe reason_career

/* variable: career_decis */
rename p23 career_decis
replace career_decis=. if career_decis==0
label define career_decis 1 "absolutely decided"  2 "very decided" 3 "decided" 4 "undecided" 5 "very undecided"
label values career_decis career_decis
inspect career_decis
describe career_decis

/* variable: career_decishow */
rename p24 career_decishow
replace career_decishow=. if career_decishow==0
label define career_decishow 1 "conversation with colleagues"  2 "information in media" 3 "family influence" 4 "teachers' influence" 5 "other reason"
label values career_decishow career_decishow
inspect career_decishow
describe career_decishow

/* variable: income_cat */
rename p25 income_cat
replace income_cat=. if income_cat==0
label define income_cat 1 "up to 1 min wage"  2 "1-3 min wage" 3 "3-5 min wage" 4 "5-10 min wage" 5 "10-15 min wage" 6 "15-20 min wage" 7 "20-30 min wage" 8 "30-40 min wage" 9 "more than 40 min wage"
label values income_cat income_cat
inspect income_cat
describe income_cat

label define member_num 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6+"

/* variable: member_live */
rename p26 member_live
replace member_live=. if member_live==0
label values member_live member_num
inspect member_live
describe member_live

/* no other option in 2002 */
label define profes 1 "high politics, business, owner large company" 2 "self-employed, manager, owner medium company" 3 "supervision or inspection of non manual activities, owner small company" 4 "non-manual repetitive occupation" 5 "supervision manual occupation" 6 "specialized manual occupation" 7 "non-specialized manual occupation" 8 "house husband/wife" 9 "other"

/* variable: profes_father */
rename p27 profes_father
replace profes_father=. if profes_father==0
label values profes_father profes
inspect profes_father
describe profes_father

/* variable: situat_father */
rename p28 situat_father
replace situat_father=. if situat_father==0
*replace situat_father=5 if situat_father==6
label define situat_father 1 "company partner or owner" 2 "self-employed" 3 "private company employee" 4 "public employee" 5 "other situation"
label values situat_father situat_father
inspect situat_father
describe situat_father

/* variable: profes_mother */
rename p29 profes_mother
replace profes_mother=. if profes_mother==0
label values profes_mother profes
inspect profes_mother
describe profes_mother

/* variable: situat_mother */
rename p30 situat_mother
replace situat_mother=. if situat_mother==0
label define situat_mother 1 "company partner or owner" 2 "self-employed" 3 "private company employee" 4 "public employee" 5 "housewife" 6 "other situation"
label values situat_mother situat_mother
inspect situat_mother
describe situat_mother

label define educ 1 "no school" 2 "primary incomplete" 3 "primary complete" 4 "low secondary incomplete" 5 "low secondary complete" 6 "high secondary incomplete" 7 "high secondary complete" 8 "university incomplete" 9 "university complete"

/* variable: educ_father */
rename p31 educ_father
replace educ_father=. if educ_father==0
label values educ_father educ
inspect educ_father
describe educ_father

/* variable: educ_mother */
rename p32 educ_mother
replace educ_mother=. if educ_mother==0
label values educ_mother educ
inspect educ_mother
describe educ_mother

/* variable: working */
rename p33 working
replace working=. if working==0
label define working 1 "no" 2 "yes, occasionally" 3 "yes, half time (up to 20h)" 4 "yes, semi integral (21h-32h)" 5 "yes, integral (more than 32h)"
label values working working
inspect working
describe working

/* variable: econ_partic */
rename p34 econ_partic
replace econ_partic=. if econ_partic==0
label define econ_partic 1 "do no work, financed by family or other" 2 "work, but also financed by family" 3 "work, finance myself" 4 "work, finance myself and help family" 5 "work, finance my family"
label values econ_partic econ_partic
inspect econ_partic
describe econ_partic

/* variable: extra_activ */
rename p35 extra_activ
replace extra_activ=. if extra_activ==0
label define extra_activ 1 "artistical and cultural" 2 "religious" 3 "political" 4 "sporting" 5 "esoterical" 6 "other" 7 "none"
label values extra_activ extra_activ
inspect extra_activ
describe extra_activ

/* variable: other_activ */
rename p36 other_activ
replace other_activ=. if other_activ==0
label define other_activ 1 "watch tv" 2 "theater or cinema" 3 "music" 4 "bar or disco" 5 "reading" 6 "sport" 7 "internet" 8 "none"
label values other_activ other_activ
inspect other_activ
describe other_activ

/* variable: news_media */
rename p37 news_media
replace news_media=. if news_media==0
label define news_media 1 "newspaper" 2 "tv news" 3 "radio news" 4 "magazine" 5 "other people" 6 "no news"
label values news_media news_media
inspect news_media
describe news_media

/* variable: read_type */
rename p38 read_typew
recode read_typew (2=1) (3=1) (4=2) (5=3) (6=4) (7=5), gen(read_type)
replace read_type=. if read_type==0
label define read_type 1 "fiction" 2 "non-fiction" 3 "poetry" 4 "other" 5 "none"
label values read_type read_type
drop read_typew
inspect read_type
describe read_type

/* variable: magazine_type */
rename p39 magazine_type
replace magazine_type=. if magazine_type==0
label define magazine_type 1 "humour or cartoon" 2 "informative" 3 "tabloid" 4 "soap opera" 5 "sporting" 6 "erotical" 7 "scientific" 8 "none"
label values magazine_type magazine_type
inspect magazine_type
describe magazine_type

/* variable: read_newspaper */
rename p40 read_newspaper
replace read_newspaper=. if read_newspaper==0
label define read_newspaper 1 "no" 2 "yes, occasionally" 3 "yes, on sundays" 4 "yes, daily"
label values read_newspaper read_newspaper
inspect read_newspaper
describe read_newspaper

/* variable: languages */
rename p41 languages
replace languages=. if languages==0
label define languages 1 "one or more very well" 2 "one or more well" 3 "one or more minimum"
label values languages languages
inspect languages
describe languages

/* variable: home_comp */
rename p42 home_comp
replace home_comp=. if home_comp==0
replace home_comp=0 if home_comp==2
label values home_comp yn
inspect home_comp
describe home_comp

/* variable: faxmodem */
rename p43 faxmodem
replace faxmodem=. if faxmodem==0
label define faxmodem 1 "only fax" 2 "bbs" 3 "internet" 4 "all previous" 5 "no fax/ modem"
label values faxmodem faxmodem
inspect faxmodem
describe faxmodem

sort inscription
merge 1:1 inscription using "Work data/QSEPR/V2000_QSEPR.dta"

compare career_choice	career_choice_pr                         
compare age       		age_pr                         
compare sex    			sex_pr                                      
compare sch_fund 		sch_fund_pr                         
compare sch_med  		sch_med_pr                        
compare type_med  		type_med_pr                        
compare prep_course 	prep_course_pr                                               
compare reason_unicamp  reason_unicamp_pr                        
compare reason_career 	reason_career_pr                         
compare income_cat  	income_cat_pr                                                     
compare member_live  	member_live_pr                        
compare profes_father 	profes_father_pr                         
compare profes_mother  	profes_mother_pr                        
compare educ_father 	educ_father_pr                         
compare educ_mother 	educ_mother_pr                         
compare working   		working_pr                       
compare read_newspaper  read_newspaper_pr

rename race_pr race
rename type_prep_pr type_prep
rename income_pr  income 			 
drop career_choice_pr age_pr sex_pr sch_fund_pr sch_med_pr type_med_pr prep_course_pr reason_unicamp_pr reason_career_pr income_cat_pr member_live_pr profes_father_pr profes_mother_pr educ_father_pr educ_mother_pr working_pr read_newspaper_pr
drop _merge

compress
save "Work data/work_data_SE.dta", replace
clear

/*  2001 */

clear
insheet using "Original data/V2001_QSETT.txt"

describe

*********************************
*							    *
* VARIABLE: LABELS AND ANALYSIS *
*								*
*********************************

rename inscri inscription
rename grupo group
rename curso career_choice
drop p48

gen year=2001
order year, after(inscription)

/* variable: sex */
rename p1 sex
replace sex=. if sex==0
label define sex 1 m 2 f
label values sex sex
inspect sex
describe sex

/* variable: age */
rename p2 age
replace age=. if age==0
label define age 1 "less than 16 years old" 2 "16 years old" 3 "17 years old" 4 "18 years old" 5 "19 years old" 6 "20 years old" 7 "21-23 years old" 8 "24-29 years old" 9 "more than 29 years old"
label values age age
inspect age
describe age

/* variable: marstat */
rename p3 marstat
replace marstat=. if marstat==0
label define marstat 1 single 2 married 3 widowed 4 divorced 5 other
label values marstat marstat
inspect marstat
describe marstat

/* variable: resid_fam_or */
/* this variable is not compatible with other years */
gen resid_fam_or=p4
replace resid_fam_or=. if resid_fam_or==0
label define resid_fam_or 1 "sao paulo metropolitan region" 2 "sao paulo inland" 3 "sao paulo coast" 4 "other state capital" 5 "other state inland" 6 "other state coast"
label values resid_fam_or resid_fam_or
inspect resid_fam_or
describe resid_fam_or

/* variable: resid_fam */
/* group to be compatible with 2003 recode */
rename p4 resid_famw
recode resid_famw (3=2) (4=3) (5=3) (6=3), gen(resid_fam)
replace resid_fam=. if resid_fam==0
label define resid_fam 1 "sao paulo metropolitan region" 2 "other region sao paulo state" 3 "other state"
label values resid_fam resid_fam
drop resid_famw
inspect resid_fam
describe resid_fam

/* variable: other_vest */
rename p5 other_vest
replace other_vest=. if other_vest==0
label define other_vest 1 "only unicamp" 2 "unicamp and fuvest" 3 "unicamp and vunesp" 4 "unicamp, fuvest and vunesp" 5 "unicamp and other private" 6 "unicamp and other public" 7 "unicamp and other public and private" 8 "other"
label values other_vest other_vest
inspect other_vest
describe other_vest

/* create a label for sch_fund and sch_med */
label define sch 1 onlypriv 2 onlypub 3 pubpriv 4 privpub 5 half 6 none

/* variable: sch_fund */
rename p6 sch_fund
replace sch_fund=. if sch_fund==0
label values sch_fund sch
inspect sch_fund
describe sch_fund

/* variable: sch_med */
rename p7 sch_med
replace sch_med=. if sch_med==0
label values sch_med sch
inspect sch_med
describe sch_med

/* variable: type_med */
rename p8 type_med
replace type_med=. if type_med==0
label define type_med 1 technical 2 "teacher training" 3 regular 4 accelerated  5 abroad 6 other
label values type_med type_med
inspect type_med
describe type_med

/* variable: period_med */
rename p9 period_med
replace period_med=. if period_med==0
label define period_med 1 morning 2 afternoon 3 evening 4 morneven 5 evenmorn 6 wholeday 7 other
label values period_med period_med
inspect period_med
describe period_med

/* variable: repeat_med */
rename p10 repeat_med
replace repeat_med=. if repeat_med==0
replace repeat_med=. if repeat_med>=6 & repeat_med<.
label define repeat_med 1 "no" 2 "yes, once" 3 "yes, twice" 4 "yes, 3 times" 5 "yes, more than 3 times"
label values repeat_med repeat_med
inspect repeat_med
describe repeat_med

/* create a label for yes and no questions */
label define yn 2 "not-appl" 1 yes 0 no

/* variable: prep_course */
rename p11 prep_course
replace prep_course=. if prep_course==0
replace prep_course=0 if prep_course==2
label values prep_course yn
inspect prep_course
describe prep_course

/* variable: reason_prep */
rename p12 reason_prep
replace reason_prep=. if reason_prep==0
replace reason_prep=. if reason_prep==9
label define reason_prep 1 "school does not prepare well" 2 "reinforce school" 3 "stop study long time ago" 4 "integrated at school" 5 "scholarship" 6 "other"
label values reason_prep reason_prep
inspect reason_prep
describe reason_prep

/* variable: durat_prep */
rename p13 durat_prep
replace durat_prep=. if durat_prep==0
label define durat_prep 1 "< 6 months" 2 "6 months-1 year" 3 "up to 1.5year" 4 "up to 2 years" 5 "more than 2 years"
label values durat_prep durat_prep
inspect durat_prep
describe durat_prep

/* variable: type_prep */
rename p14 type_prep
replace type_prep=. if type_prep==0
label define type_prep 1 commercial 2 community 
label values type_prep type_prep
inspect type_prep
describe type_prep

/* variable: scholars_prep */
rename p15 scholars_prep
replace scholars_prep=. if scholars_prep==0
label define scholars_prep 1 "yes, merit" 2 "yes, economic" 3 "yes, other" 4 "no"
label values scholars_prep scholars_prep
inspect scholars_prep
describe scholars_prep

/* variable: period_prep */
rename p16 period_prep
replace period_prep=. if period_prep==0
label define period_prep 1 "morning" 2 "afternoon" 3 "evening" 4 "other"
label values period_prep period_prep
inspect period_prep
describe period_prep

/* variable: charac_prep */
rename p17 charac_prep
replace charac_prep=. if charac_prep==0
label define charac_prep 1 "less than 30 students" 2 "30-50 students" 3 "51-100 students" 4 "101+ students"
label values charac_prep charac_prep
inspect charac_prep
describe charac_prep

/* variable: reason_noprep */
rename p18 reason_noprep
replace reason_noprep=. if reason_noprep==0
label define reason_noprep 1 "school prepares well" 2 "economic difficulties" 3 "coincide with work time" 4 "thought could study alone" 5 "no prep close to home" 6 "school offers integrated" 7 "other"
label values reason_noprep reason_noprep
inspect reason_noprep
describe reason_noprep

/* variable: vest_before */
rename p19 vest_before
replace vest_before=. if vest_before==0
label define vest_before 1 "no" 2 "yes, one" 3 "yes, twice" 4 "yes, three" 5 "yes, more than three"
label values vest_before vest_before
inspect vest_before
describe vest_before

/* variable: vest_beforwhere */
rename p20 vest_beforwhere
replace vest_beforwhere=. if vest_beforwhere==0
label define vest_beforwhere 1 "only unicamp" 2 "unicamp and other public" 3 "only other public" 4 "unicamp and private" 5 "only private" 6 "unicamp and other public and private" 7 "only other public and private"
label values vest_beforwhere vest_beforwhere
inspect vest_beforwhere
describe vest_beforwhere

/* variable: other_univ */
rename p21 other_univ
replace other_univ=. if other_univ==0
replace other_univ=0 if other_univ==2
label values other_univ yn
inspect other_univ
describe other_univ

/* variable: other_univreas */
rename p22 other_univreas
replace other_univreas=. if other_univreas==0
label define other_univreas 1 "dropped out" 2 "over" 3 "will give up" 4 "do both" 5 "keep other, only experience vestibular" 6 "other"
label values other_univreas other_univreas
inspect  other_univreas
describe other_univreas

/* variable: other_univinst */
rename p23 other_univinst
replace other_univinst=. if other_univinst==0
label define other_univinst 1 "usp" 2 "unicamp" 3 "unesp" 4 "puc-sp" 5 "puc-campinas" 6 "federal or state university" 7 "private institution" 8 "other"
label values other_univinst other_univinst
inspect  other_univinst
describe other_univinst

/* variable: other_univdropreas */
rename p24 other_univdropreas
replace other_univdropreas=. if other_univdropreas==0
label define other_univdropreas 1 "not preferred career" 2 "not preferred university" 3 "disappointed with course" 4 "change in professional option" 5 "financial reasons" 6 "start working" 7 "not able to follow the course" 8 "other reasons"
label values other_univdropreas other_univdropreas
inspect  other_univdropreas
describe other_univdropreas

/* variable: reason_unicamp */
rename p25 reason_unicamp
replace reason_unicamp=. if reason_unicamp==0
label define reason_unicamp 1 "best for the course"  2 "free" 3 "close to residence" 4 "friends" 5 "reputation" 6 "rich cultural university life" 7 "access to scientific career" 8 "other"
label values reason_unicamp reason_unicamp
inspect reason_unicamp
describe reason_unicamp

/* variable: reason_career */
rename p26 reason_career
replace reason_career=. if reason_career==0
label define reason_career 1 "personal ability"  2 "social status" 3 "jobmarket" 4 "contribution to society" 5 "low competition for access" 6 "personal realization" 7 "other"
label values reason_career reason_career
inspect reason_career
describe reason_career

/* variable: career_decis */
rename p27 career_decis
replace career_decis=. if career_decis==0
label define career_decis 1 "absolutely decided"  2 "very decided" 3 "decided" 4 "undecided" 5 "very undecided"
label values career_decis career_decis
inspect career_decis
describe career_decis

/* variable: career_decishow */
rename p28 career_decishow
replace career_decishow=. if career_decishow==0
label define career_decishow 1 "conversation with colleagues"  2 "information in media" 3 "family influence" 4 "teachers' influence" 5 "other reason"
label values career_decishow career_decishow
inspect career_decishow
describe career_decishow

/* variable: income_cat */
rename p29 income_cat
replace income_cat=. if income_cat==0
label define income_cat 1 "up to 1 min wage"  2 "1-3 min wage" 3 "3-5 min wage" 4 "5-10 min wage" 5 "10-15 min wage" 6 "15-20 min wage" 7 "20-30 min wage" 8 "30-40 min wage" 9 "more than 40 min wage"
label values income_cat income_cat
inspect income_cat
describe income_cat

label define member_num 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6+"

/* variable: member_live */
rename p30 member_live
replace member_live=. if member_live==0
label values member_live member_num
inspect member_live
describe member_live

/* no other option in 2002 */
label define profes 1 "high politics, business, owner large company" 2 "self-employed, manager, owner medium company" 3 "supervision or inspection of non manual activities, owner small company" 4 "non-manual repetitive occupation" 5 "supervision manual occupation" 6 "specialized manual occupation" 7 "non-specialized manual occupation" 8 "house husband/wife" 9 "other"

/* variable: profes_father */
rename p31 profes_father
replace profes_father=. if profes_father==0
label values profes_father profes
inspect profes_father
describe profes_father

/* variable: situat_father */
rename p32 situat_father
replace situat_father=. if situat_father==0
*replace situat_father=5 if situat_father==6
label define situat_father 1 "company partner or owner" 2 "self-employed" 3 "private company employee" 4 "public employee" 5 "other situation"
label values situat_father situat_father
inspect situat_father
describe situat_father

/* variable: profes_mother */
rename p33 profes_mother
replace profes_mother=. if profes_mother==0
label values profes_mother profes
inspect profes_mother
describe profes_mother

/* variable: situat_mother */
rename p34 situat_mother
replace situat_mother=. if situat_mother==0
label define situat_mother 1 "company partner or owner" 2 "self-employed" 3 "private company employee" 4 "public employee" 5 "housewife" 6 "other situation"
label values situat_mother situat_mother
inspect situat_mother
describe situat_mother

label define educ 1 "no school" 2 "primary incomplete" 3 "primary complete" 4 "low secondary incomplete" 5 "low secondary complete" 6 "high secondary incomplete" 7 "high secondary complete" 8 "university incomplete" 9 "university complete"

/* variable: educ_father */
rename p35 educ_father
replace educ_father=. if educ_father==0
label values educ_father educ
inspect educ_father
describe educ_father

/* variable: educ_mother */
rename p36 educ_mother
replace educ_mother=. if educ_mother==0
label values educ_mother educ
inspect educ_mother
describe educ_mother

/* variable: working */
rename p37 working
replace working=. if working==0
label define working 1 "no" 2 "yes, occasionally" 3 "yes, half time (up to 20h)" 4 "yes, semi integral (21h-32h)" 5 "yes, integral (more than 32h)"
label values working working
inspect working
describe working

/* variable: econ_partic */
rename p38 econ_partic
replace econ_partic=. if econ_partic==0
label define econ_partic 1 "do no work, financed by family or other" 2 "work, but also financed by family" 3 "work, finance myself" 4 "work, finance myself and help family" 5 "work, finance my family"
label values econ_partic econ_partic
inspect econ_partic
describe econ_partic

/* variable: extra_activ */
rename p39 extra_activ
replace extra_activ=. if extra_activ==0
label define extra_activ 1 "artistical and cultural" 2 "religious" 3 "political" 4 "sporting" 5 "esoterical" 6 "other" 7 "none"
label values extra_activ extra_activ
inspect extra_activ
describe extra_activ

/* variable: other_activ */
rename p40 other_activ
replace other_activ=. if other_activ==0
label define other_activ 1 "watch tv" 2 "theater or cinema" 3 "music" 4 "bar or disco" 5 "reading" 6 "sport" 7 "internet" 8 "none"
label values other_activ other_activ
inspect other_activ
describe other_activ

/* variable: news_media */
rename p41 news_media
replace news_media=. if news_media==0
label define news_media 1 "newspaper" 2 "tv news" 3 "radio news" 4 "magazine" 5 "other people" 6 "no news"
label values news_media news_media
inspect news_media
describe news_media

/* variable: read_type */
rename p42 read_typew
recode read_typew (2=1) (3=1) (4=2) (5=3) (6=4) (7=5), gen(read_type)
replace read_type=. if read_type==0
label define read_type 1 "fiction" 2 "non-fiction" 3 "poetry" 4 "other" 5 "none"
label values read_type read_type
drop read_typew
inspect read_type
describe read_type

/* variable: magazine_type */
rename p43 magazine_type
replace magazine_type=. if magazine_type==0
label define magazine_type 1 "humour or cartoon" 2 "informative" 3 "tabloid" 4 "soap opera" 5 "sporting" 6 "erotical" 7 "scientific" 8 "none"
label values magazine_type magazine_type
inspect magazine_type
describe magazine_type

/* variable: read_newspaper */
rename p44 read_newspaper
replace read_newspaper=. if read_newspaper==0
label define read_newspaper 1 "no" 2 "yes, occasionally" 3 "yes, on sundays" 4 "yes, daily"
label values read_newspaper read_newspaper
inspect read_newspaper
describe read_newspaper

/* variable: languages */
rename p45 languages
replace languages=. if languages==0
label define languages 1 "one or more very well" 2 "one or more well" 3 "one or more minimum"
label values languages languages
inspect languages
describe languages

/* variable: home_comp */
rename p46 home_comp
replace home_comp=. if home_comp==0
replace home_comp=0 if home_comp==2
label values home_comp yn
inspect home_comp
describe home_comp

/* variable: home_faxmodem */
rename p47 home_faxmodem
replace home_faxmodem=. if home_faxmodem==0
label define home_faxmodem 1 "only fax" 2 "bbs" 3 "internet" 4 "all previous" 5 "no fax/ modem"
label values home_faxmodem home_faxmodem
inspect home_faxmodem
describe home_faxmodem

sort inscription
merge 1:1 inscription using "Work data/QSEPR/V2001_QSEPR.dta"

compare career_choice	career_choice_pr                         
compare age       		age_pr                         
compare sex    			sex_pr                                      
compare sch_fund 		sch_fund_pr                         
compare sch_med  		sch_med_pr                        
compare type_med  		type_med_pr                        
compare prep_course 	prep_course_pr
compare type_prep_pr 	type_prep                                             
compare reason_unicamp  reason_unicamp_pr                        
compare reason_career 	reason_career_pr                         
compare income_cat  	income_cat_pr                                                     
compare member_live  	member_live_pr                        
compare profes_father 	profes_father_pr                         
compare profes_mother  	profes_mother_pr                        
compare educ_father 	educ_father_pr                         
compare educ_mother 	educ_mother_pr                         
compare working   		working_pr                       
compare read_newspaper  read_newspaper_pr

rename race_pr race
rename income_pr  income 			 
drop career_choice_pr age_pr sex_pr sch_fund_pr sch_med_pr type_med_pr prep_course_pr type_prep_pr reason_unicamp_pr reason_career_pr income_cat_pr member_live_pr profes_father_pr profes_mother_pr educ_father_pr educ_mother_pr working_pr read_newspaper_pr
drop _merge

append using "Work data/work_data_SE.dta"
compress
save "Work data/work_data_SE.dta", replace
clear

/* 2002 */

clear
insheet using "Original data/V2002_QSETT.txt"

describe

*********************************
*							    *
* VARIABLE: LABELS AND ANALYSIS *
*								*
*********************************

rename inscri inscription
rename grupo group
rename curso career_choice
drop p48

gen year=2002
order year, after(inscription)

/* variable: sex */
rename p1 sex
replace sex=. if sex==0
label define sex 1 m 2 f
label values sex sex
inspect sex
describe sex

/* variable: age */
rename p2 age
replace age=. if age==0
label define age 1 "less than 16 years old" 2 "16 years old" 3 "17 years old" 4 "18 years old" 5 "19 years old" 6 "20 years old" 7 "21-23 years old" 8 "24-29 years old" 9 "more than 29 years old"
label values age age
inspect age
describe age

/* variable: marstat */
rename p3 marstat
replace marstat=. if marstat==0
label define marstat 1 single 2 married 3 widowed 4 divorced 5 other
label values marstat marstat
inspect marstat
describe marstat

/* variable: resid_fam_or */
/* this variable is not compatible with other years */
gen resid_fam_or=p4
replace resid_fam_or=. if resid_fam_or==0
label define resid_fam_or 1 "sao paulo metropolitan region" 2 "sao paulo inland" 3 "sao paulo coast" 4 "other state capital" 5 "other state inland" 6 "other state coast"
label values resid_fam_or resid_fam_or
inspect resid_fam_or
describe resid_fam_or

/* variable: resid_fam */
/* group to be compatible with 2003 recode */
rename p4 resid_famw
recode resid_famw (3=2) (4=3) (5=3) (6=3), gen(resid_fam)
replace resid_fam=. if resid_fam==0
label define resid_fam 1 "sao paulo metropolitan region" 2 "other region sao paulo state" 3 "other state"
label values resid_fam resid_fam
drop resid_famw
inspect resid_fam
describe resid_fam

/* variable: other_vest */
rename p5 other_vest
replace other_vest=. if other_vest==0
label define other_vest 1 "only unicamp" 2 "unicamp and fuvest" 3 "unicamp and vunesp" 4 "unicamp, fuvest and vunesp" 5 "unicamp and other private" 6 "unicamp and other public" 7 "unicamp and other public and private" 8 "other"
label values other_vest other_vest
inspect other_vest
describe other_vest

/* create a label for sch_fund and sch_med */
label define sch 1 onlypriv 2 onlypub 3 pubpriv 4 privpub 5 half 6 none

/* variable: sch_fund */
rename p6 sch_fund
replace sch_fund=. if sch_fund==0
label values sch_fund sch
inspect sch_fund
describe sch_fund

/* variable: sch_med */
rename p7 sch_med
replace sch_med=. if sch_med==0
label values sch_med sch
inspect sch_med
describe sch_med

/* variable: type_med */
rename p8 type_med
replace type_med=. if type_med==0
label define type_med 1 technical 2 "teacher training" 3 regular 4 accelerated  5 abroad 6 other
label values type_med type_med
inspect type_med
describe type_med

/* variable: period_med */
rename p9 period_med
replace period_med=. if period_med==0
label define period_med 1 morning 2 afternoon 3 evening 4 morneven 5 evenmorn 6 wholeday 7 other
label values period_med period_med
inspect period_med
describe period_med

/* variable: repeat_med */
rename p10 repeat_med
replace repeat_med=. if repeat_med==0
replace repeat_med=. if repeat_med>=6 & repeat_med<.
label define repeat_med 1 "no" 2 "yes, once" 3 "yes, twice" 4 "yes, 3 times" 5 "yes, more than 3 times"
label values repeat_med repeat_med
inspect repeat_med
describe repeat_med

/* create a label for yes and no questions */
label define yn 2 "not-appl" 1 yes 0 no

/* variable: prep_course */
rename p11 prep_course
replace prep_course=. if prep_course==0
replace prep_course=0 if prep_course==2
label values prep_course yn
inspect prep_course
describe prep_course

/* variable: reason_prep */
rename p12 reason_prep
replace reason_prep=. if reason_prep==0
replace reason_prep=. if reason_prep==9
label define reason_prep 1 "school does not prepare well" 2 "reinforce school" 3 "stop study long time ago" 4 "integrated at school" 5 "scholarship" 6 "other"
label values reason_prep reason_prep
inspect reason_prep
describe reason_prep

/* variable: durat_prep */
rename p13 durat_prep
replace durat_prep=. if durat_prep==0
label define durat_prep 1 "< 6 months" 2 "6 months-1 year" 3 "up to 1.5year" 4 "up to 2 years" 5 "more than 2 years"
label values durat_prep durat_prep
inspect durat_prep
describe durat_prep

/* variable: type_prep */
rename p14 type_prep
replace type_prep=. if type_prep==0
label define type_prep 1 commercial 2 community 
label values type_prep type_prep
inspect type_prep
describe type_prep

/* variable: scholars_prep */
rename p15 scholars_prep
replace scholars_prep=. if scholars_prep==0
label define scholars_prep 1 "yes, merit" 2 "yes, economic" 3 "yes, other" 4 "no"
label values scholars_prep scholars_prep
inspect scholars_prep
describe scholars_prep

/* variable: period_prep */
rename p16 period_prep
replace period_prep=. if period_prep==0
label define period_prep 1 "morning" 2 "afternoon" 3 "evening" 4 "other"
label values period_prep period_prep
inspect period_prep
describe period_prep

/* variable: charac_prep */
rename p17 charac_prep
replace charac_prep=. if charac_prep==0
label define charac_prep 1 "less than 30 students" 2 "30-50 students" 3 "51-100 students" 4 "101+ students"
label values charac_prep charac_prep
inspect charac_prep
describe charac_prep

/* variable: reason_noprep */
rename p18 reason_noprep
replace reason_noprep=. if reason_noprep==0
label define reason_noprep 1 "school prepares well" 2 "economic difficulties" 3 "coincide with work time" 4 "thought could study alone" 5 "no prep close to home" 6 "school offers integrated" 7 "other"
label values reason_noprep reason_noprep
inspect reason_noprep
describe reason_noprep

/* variable: vest_before */
rename p19 vest_before
replace vest_before=. if vest_before==0
label define vest_before 1 "no" 2 "yes, one" 3 "yes, twice" 4 "yes, three" 5 "yes, more than three"
label values vest_before vest_before
inspect vest_before
describe vest_before

/* variable: vest_beforwhere */
rename p20 vest_beforwhere
replace vest_beforwhere=. if vest_beforwhere==0
label define vest_beforwhere 1 "only unicamp" 2 "unicamp and other public" 3 "only other public" 4 "unicamp and private" 5 "only private" 6 "unicamp and other public and private" 7 "only other public and private"
label values vest_beforwhere vest_beforwhere
inspect vest_beforwhere
describe vest_beforwhere

/* variable: other_univ */
rename p21 other_univ
replace other_univ=. if other_univ==0
replace other_univ=0 if other_univ==2
label values other_univ yn
inspect other_univ
describe other_univ

/* variable: other_univreas */
rename p22 other_univreas
replace other_univreas=. if other_univreas==0
label define other_univreas 1 "dropped out" 2 "over" 3 "will give up" 4 "do both" 5 "keep other, only experience vestibular" 6 "other"
label values other_univreas other_univreas
inspect  other_univreas
describe other_univreas

/* variable: other_univinst */
rename p23 other_univinst
replace other_univinst=. if other_univinst==0
label define other_univinst 1 "usp" 2 "unicamp" 3 "unesp" 4 "puc-sp" 5 "puc-campinas" 6 "federal or state university" 7 "private institution" 8 "other"
label values other_univinst other_univinst
inspect  other_univinst
describe other_univinst

/* variable: other_univdropreas */
rename p24 other_univdropreas
replace other_univdropreas=. if other_univdropreas==0
label define other_univdropreas 1 "not preferred career" 2 "not preferred university" 3 "disappointed with course" 4 "change in professional option" 5 "financial reasons" 6 "start working" 7 "not able to follow the course" 8 "other reasons"
label values other_univdropreas other_univdropreas
inspect  other_univdropreas
describe other_univdropreas

/* variable: reason_unicamp */
rename p25 reason_unicamp
replace reason_unicamp=. if reason_unicamp==0
label define reason_unicamp 1 "best for the course"  2 "free" 3 "close to residence" 4 "friends" 5 "reputation" 6 "rich cultural university life" 7 "access to scientific career" 8 "other"
label values reason_unicamp reason_unicamp
inspect reason_unicamp
describe reason_unicamp

/* variable: reason_career */
rename p26 reason_career
replace reason_career=. if reason_career==0
label define reason_career 1 "personal ability"  2 "social status" 3 "jobmarket" 4 "contribution to society" 5 "low competition for access" 6 "personal realization" 7 "other"
label values reason_career reason_career
inspect reason_career
describe reason_career

/* variable: career_decis */
rename p27 career_decis
replace career_decis=. if career_decis==0
label define career_decis 1 "absolutely decided"  2 "very decided" 3 "decided" 4 "undecided" 5 "very undecided"
label values career_decis career_decis
inspect career_decis
describe career_decis

/* variable: career_decishow */
rename p28 career_decishow
replace career_decishow=. if career_decishow==0
label define career_decishow 1 "conversation with colleagues"  2 "information in media" 3 "family influence" 4 "teachers' influence" 5 "other reason"
label values career_decishow career_decishow
inspect career_decishow
describe career_decishow

/* variable: income_cat */
rename p29 income_cat
replace income_cat=. if income_cat==0
label define income_cat 1 "up to 1 min wage"  2 "1-3 min wage" 3 "3-5 min wage" 4 "5-10 min wage" 5 "10-15 min wage" 6 "15-20 min wage" 7 "20-30 min wage" 8 "30-40 min wage" 9 "more than 40 min wage"
label values income_cat income_cat
inspect income_cat
describe income_cat

label define member_num 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6+"

/* variable: member_live */
rename p30 member_live
replace member_live=. if member_live==0
label values member_live member_num
inspect member_live
describe member_live

/* no other option in 2002 */
label define profes 1 "high politics, business, owner large company" 2 "self-employed, manager, owner medium company" 3 "supervision or inspection of non manual activities, owner small company" 4 "non-manual repetitive occupation" 5 "supervision manual occupation" 6 "specialized manual occupation" 7 "non-specialized manual occupation" 8 "house husband/wife" 9 "other"

/* variable: profes_father */
rename p31 profes_father
replace profes_father=. if profes_father==0
label values profes_father profes
inspect profes_father
describe profes_father

/* variable: situat_father */
rename p32 situat_father
replace situat_father=. if situat_father==0
label define situat_father 1 "company partner or owner" 2 "self-employed" 3 "private company employee" 4 "public employee" 5 "other situation"
label values situat_father situat_father
inspect situat_father
describe situat_father

/* variable: profes_mother */
rename p33 profes_mother
replace profes_mother=. if profes_mother==0
label values profes_mother profes
inspect profes_mother
describe profes_mother

/* variable: situat_mother */
rename p34 situat_mother
replace situat_mother=. if situat_mother==0
label define situat_mother 1 "company partner or owner" 2 "self-employed" 3 "private company employee" 4 "public employee" 5 "housewife" 6 "other situation"
label values situat_mother situat_mother
inspect situat_mother
describe situat_mother

label define educ 1 "no school" 2 "primary incomplete" 3 "primary complete" 4 "low secondary incomplete" 5 "low secondary complete" 6 "high secondary incomplete" 7 "high secondary complete" 8 "university incomplete" 9 "university complete"

/* variable: educ_father */
rename p35 educ_father
replace educ_father=. if educ_father==0
label values educ_father educ
inspect educ_father
describe educ_father

/* variable: educ_mother */
rename p36 educ_mother
replace educ_mother=. if educ_mother==0
label values educ_mother educ
inspect educ_mother
describe educ_mother

/* variable: working */
rename p37 working
replace working=. if working==0
label define working 1 "no" 2 "yes, occasionally" 3 "yes, half time (up to 20h)" 4 "yes, semi integral (21h-32h)" 5 "yes, integral (more than 32h)"
label values working working
inspect working
describe working

/* variable: econ_partic */
rename p38 econ_partic
replace econ_partic=. if econ_partic==0
label define econ_partic 1 "do no work, financed by family or other" 2 "work, but also financed by family" 3 "work, finance myself" 4 "work, finance myself and help family" 5 "work, finance my family"
label values econ_partic econ_partic
inspect econ_partic
describe econ_partic

/* variable: extra_activ */
rename p39 extra_activ
replace extra_activ=. if extra_activ==0
label define extra_activ 1 "artistical and cultural" 2 "religious" 3 "political" 4 "sporting" 5 "esoterical" 6 "other" 7 "none"
label values extra_activ extra_activ
inspect extra_activ
describe extra_activ

/* variable: other_activ */
rename p40 other_activ
replace other_activ=. if other_activ==0
label define other_activ 1 "watch tv" 2 "theater or cinema" 3 "music" 4 "bar or disco" 5 "reading" 6 "sport" 7 "internet" 8 "none"
label values other_activ other_activ
inspect other_activ
describe other_activ

/* variable: news_media */
rename p41 news_media
replace news_media=. if news_media==0
label define news_media 1 "newspaper" 2 "tv news" 3 "radio news" 4 "magazine" 5 "other people" 6 "no news"
label values news_media news_media
inspect news_media
describe news_media

/* variable: read_type */
rename p42 read_typew
recode read_typew (2=3) (3=1) (4=1) (5=4) (6=2) (7=2) (8=5), gen(read_type)
replace read_type=. if read_type==0
label define read_type 1 "fiction" 2 "non-fiction" 3 "poetry" 4 "other" 5 "none"
label values read_type read_type
drop read_typew
inspect read_type
describe read_type

/* variable: magazine_type */
rename p43 magazine_type
replace magazine_type=. if magazine_type==0
label define magazine_type 1 "humour or cartoon" 2 "informative" 3 "tabloid" 4 "soap opera" 5 "sporting" 6 "erotical" 7 "scientific" 8 "none"
label values magazine_type magazine_type
inspect magazine_type
describe magazine_type

/* variable: read_newspaper */
rename p44 read_newspaper
replace read_newspaper=. if read_newspaper==0
label define read_newspaper 1 "no" 2 "yes, occasionally" 3 "yes, on sundays" 4 "yes, daily"
label values read_newspaper read_newspaper
inspect read_newspaper
describe read_newspaper

/* variable: languages */
rename p45 languages
replace languages=. if languages==0
label define languages 1 "one or more very well" 2 "one or more well" 3 "one or more minimum"
label values languages languages
inspect languages
describe languages

/* variable: home_comp */
rename p46 home_comp
replace home_comp=. if home_comp==0
replace home_comp=0 if home_comp==2
label values home_comp yn
inspect home_comp
describe home_comp

/* variable: faxmodem */
rename p47 faxmodem
replace faxmodem=. if faxmodem==0
label define faxmodem 1 "only fax" 2 "bbs" 3 "internet" 4 "all previous" 5 "no fax/ modem"
label values faxmodem faxmodem
inspect faxmodem
describe faxmodem

sort inscription
merge 1:1 inscription using "Work data/QSEPR/V2002_QSEPR.dta"

compare career_choice	career_choice_pr                         
compare age       		age_pr                         
compare sex    			sex_pr                                      
compare sch_fund 		sch_fund_pr                         
compare sch_med  		sch_med_pr                        
compare type_med  		type_med_pr                        
compare prep_course 	prep_course_pr
compare type_prep_pr 	type_prep                                             
compare reason_unicamp  reason_unicamp_pr                        
compare reason_career 	reason_career_pr                         
compare income_cat  	income_cat_pr                                                     
compare member_live  	member_live_pr                        
compare profes_father 	profes_father_pr                         
compare profes_mother  	profes_mother_pr                        
compare educ_father 	educ_father_pr                         
compare educ_mother 	educ_mother_pr                         
compare working   		working_pr                       
compare read_newspaper  read_newspaper_pr

rename race_pr race
rename income_pr  income 			 
drop career_choice_pr age_pr sex_pr sch_fund_pr sch_med_pr type_med_pr prep_course_pr type_prep_pr reason_unicamp_pr reason_career_pr income_cat_pr member_live_pr profes_father_pr profes_mother_pr educ_father_pr educ_mother_pr working_pr read_newspaper_pr
drop _merge

append using "Work data/work_data_SE.dta"
compress
save "Work data/work_data_SE.dta", replace
clear

/* 2003 */

clear
insheet using "Original data/V2003_QSETT.txt"

describe

*********************************
*							    *
* VARIABLE: LABELS AND ANALYSIS *
*								*
*********************************

rename inscri inscription
rename grupo group
rename curso career_choice

gen year=2003
order year, after(inscription)

/* variable: sex */
rename p1 sex
replace sex=. if sex==0
label define sex 1 m 2 f
label values sex sex
inspect sex
describe sex

/* variable: age */
rename p2 age
replace age=. if age==0
label define age 1 "less than 16 years old" 2 "16 years old" 3 "17 years old" 4 "18 years old" 5 "19 years old" 6 "20 years old" 7 "21-23 years old" 8 "24-29 years old" 9 "more than 29 years old"
label values age age
inspect age
describe age

/* variable: marstat */
rename p3 marstat
replace marstat=. if marstat==0
label define marstat 1 single 2 married 3 widowed 4 divorced 5 other
label values marstat marstat
inspect marstat
describe marstat

/* variable: race */
rename p4 race
replace race=. if race==0
label define race 1 white 2 black 3 mulatto 4 asian 5 native
label values race race
inspect race
describe race

/* variable: resid_fam_or */
/* this variable is not compatible with other years */
gen resid_fam_or=p5
replace resid_fam_or=. if resid_fam_or==0
label define resid_fam_or 1 "sao paulo metropolitan region" 2 "sao paulo inland" 3 "sao paulo coast" 4 "other state capital" 5 "other state inland" 6 "other state coast"
label values resid_fam_or resid_fam_or
inspect resid_fam_or
describe resid_fam_or

/* variable: resid_fam */
/* group to be compatible with 2003 recode */
rename p5 resid_famw
recode resid_famw (3=2) (4=3) (5=3) (6=3), gen(resid_fam)
replace resid_fam=. if resid_fam==0
label define resid_fam 1 "sao paulo metropolitan region" 2 "other region sao paulo state" 3 "other state"
label values resid_fam resid_fam
drop resid_famw
inspect resid_fam
describe resid_fam

/* variable: other_vest */
rename p6 other_vest
replace other_vest=. if other_vest==0
label define other_vest 1 "only unicamp" 2 "unicamp and fuvest" 3 "unicamp and vunesp" 4 "unicamp, fuvest and vunesp" 5 "unicamp and other private" 6 "unicamp and other public" 7 "unicamp and other public and private" 8 "other"
label values other_vest other_vest
inspect other_vest
describe other_vest

/* create a label for sch_fund and sch_med */
label define sch 1 onlypriv 2 onlypub 3 pubpriv 4 privpub 5 half 6 none

/* variable: sch_fund */
rename p7 sch_fund
replace sch_fund=. if sch_fund==0
label values sch_fund sch
inspect sch_fund
describe sch_fund

/* variable: sch_med */
rename p8 sch_med
replace sch_med=. if sch_med==0
label values sch_med sch
inspect sch_med
describe sch_med

/* variable: type_med */
rename p9 type_med
replace type_med=. if type_med==0
label define type_med 1 technical 2 "teacher training" 3 regular 4 accelerated  5 abroad 6 other
label values type_med type_med
inspect type_med
describe type_med

/* variable: type_tech */
rename p10 type_tech
replace type_tech=. if type_tech==0
label define type_tech 1 "related to a public university, federal or state center" 2 "related to an institution" 3 "private" 4 "magisterio"  5 "other"
label values type_tech type_tech
inspect type_tech
describe type_tech

/* variable: period_med */
rename p11 period_med
replace period_med=. if period_med==0
label define period_med 1 morning 2 afternoon 3 evening 4 morneven 5 evenmorn 6 wholeday 7 other
label values period_med period_med
inspect period_med
describe period_med

/* variable: repeat_med */
rename p12 repeat_med
replace repeat_med=. if repeat_med==0
label define repeat_med 1 "no" 2 "yes, once" 3 "yes, twice" 4 "yes, 3 times" 5 "yes, more than 3 times"
label values repeat_med repeat_med
inspect repeat_med
describe repeat_med

/* variable: dropout_fundmed */
rename p13 dropout_fundmed
replace dropout_fundmed=. if dropout_fundmed==0
label define dropout_fundmed 1 "yes, during fundamental" 2 "yes, during medio" 3 "yes, during both" 4 "never"
label values dropout_fundmed dropout_fundmed
inspect dropout_fundmed
describe dropout_fundmed

/* variable: dropout_reas */
rename p14 dropout_reas
replace dropout_reas=. if dropout_reas==0
label define dropout_reas 1 "need to work" 2 "difficult to finance study" 3 "lack of motivation or family incentive" 4 "repetition" 5 "dissatisfaction with school" 6 "military service" 7 "other"
label values dropout_reas dropout_reas
inspect dropout_reas
describe dropout_reas

/* variable: dropout_period */
rename p15 dropout_period
replace dropout_period=. if dropout_period==0
label define dropout_period 1 "less than 1 year" 2 "1 year" 3 "2 years" 4 "3 years" 5 "4 years or more"
label values dropout_period dropout_period
inspect dropout_period
describe dropout_period

/* create a label for yes and no questions */
label define yn 2 "not-appl" 1 yes 0 no

/* variable: prep_course */
rename p16 prep_course
replace prep_course=. if prep_course==0
replace prep_course=0 if prep_course==2
label values prep_course yn
inspect prep_course
describe prep_course

/* variable: reason_prep */
rename p17 reason_prep
replace reason_prep=. if reason_prep==0
label define reason_prep 1 "school does not prepare well" 2 "reinforce school" 3 "stop study long time ago" 4 "integrated at school" 5 "scholarship" 6 "other"
label values reason_prep reason_prep
inspect reason_prep
describe reason_prep

/* variable: durat_prep */
rename p18 durat_prep
replace durat_prep=. if durat_prep==0
label define durat_prep 1 "< 6 months" 2 "6 months-1 year" 3 "up to 1.5year" 4 "up to 2 years" 5 "more than 2 years"
label values durat_prep durat_prep
inspect durat_prep
describe durat_prep

/* variable: type_prep */
rename p19 type_prep
replace type_prep=. if type_prep==0
label define type_prep 1 commercial 2 community 
label values type_prep type_prep
inspect type_prep
describe type_prep

/* variable: scholars_prep */
rename p20 scholars_prep
replace scholars_prep=. if scholars_prep==0
label define scholars_prep 1 "yes, merit" 2 "yes, economic" 3 "yes, other" 4 "no"
label values scholars_prep scholars_prep
inspect scholars_prep
describe scholars_prep

/* variable: period_prep */
rename p21 period_prep
replace period_prep=. if period_prep==0
label define period_prep 1 "morning" 2 "afternoon" 3 "evening" 4 "other"
label values period_prep period_prep
inspect period_prep
describe period_prep

/* variable: charac_prep */
rename p22 charac_prep
replace charac_prep=. if charac_prep==0
label define charac_prep 1 "less than 30 students" 2 "30-50 students" 3 "51-100 students" 4 "101+ students"
label values charac_prep charac_prep
inspect charac_prep
describe charac_prep

/* variable: reason_noprep */
rename p23 reason_noprep
replace reason_noprep=. if reason_noprep==0
label define reason_noprep 1 "school prepares well" 2 "economic difficulties" 3 "coincide with work time" 4 "thought could study alone" 5 "no prep close to home" 6 "school offers integrated" 7 "other"
label values reason_noprep reason_noprep
inspect reason_noprep
describe reason_noprep

/* variable: vest_before */
rename p24 vest_before
replace vest_before=. if vest_before==0
label define vest_before 1 "no" 2 "yes, one" 3 "yes, twice" 4 "yes, three" 5 "yes, more than three"
label values vest_before vest_before
inspect vest_before
describe vest_before

/* variable: vest_beforwhere */
rename p25 vest_beforwhere
replace vest_beforwhere=. if vest_beforwhere==0
label define vest_beforwhere 1 "only unicamp" 2 "unicamp and other public" 3 "only other public" 4 "unicamp and private" 5 "only private" 6 "unicamp and other public and private" 7 "only other public and private"
label values vest_beforwhere vest_beforwhere
inspect vest_beforwhere
describe vest_beforwhere

/* variable: other_univ */
rename p26 other_univ
replace other_univ=. if other_univ==0
replace other_univ=0 if other_univ==2
label values other_univ yn
inspect other_univ
describe other_univ

/* variable: other_univreas */
rename p27 other_univreas
replace other_univreas=. if other_univreas==0
label define other_univreas 1 "dropped out" 2 "over" 3 "will give up" 4 "do both" 5 "keep other, only experience vestibular" 6 "other"
label values other_univreas other_univreas
inspect  other_univreas
describe other_univreas

/* variable: other_univinst */
rename p28 other_univinst
replace other_univinst=. if other_univinst==0
label define other_univinst 1 "usp" 2 "unicamp" 3 "unesp" 4 "puc-sp" 5 "puc-campinas" 6 "federal or state university" 7 "private institution" 8 "other"
label values other_univinst other_univinst
inspect  other_univinst
describe other_univinst

/* variable: other_univdropreas */
rename p29 other_univdropreas
replace other_univdropreas=. if other_univdropreas==0
label define other_univdropreas 1 "not preferred career" 2 "not preferred university" 3 "disappointed with course" 4 "change in professional option" 5 "financial reasons" 6 "start working" 7 "not able to follow the course" 8 "other reasons"
label values other_univdropreas other_univdropreas
inspect  other_univdropreas
describe other_univdropreas

/* variable: reason_unicamp */
rename p30 reason_unicamp
replace reason_unicamp=. if reason_unicamp==0
label define reason_unicamp 1 "best for the course"  2 "free" 3 "close to residence" 4 "friends" 5 "reputation" 6 "rich cultural university life" 7 "access to scientific career" 8 "other"
label values reason_unicamp reason_unicamp
inspect reason_unicamp
describe reason_unicamp

/* variable: reason_career */
rename p31 reason_career
replace reason_career=. if reason_career==0
label define reason_career 1 "personal ability"  2 "social status" 3 "jobmarket" 4 "contribution to society" 5 "low competition for access" 6 "personal realization" 7 "other"
label values reason_career reason_career
inspect reason_career
describe reason_career

/* variable: career_decis */
rename p32 career_decis
replace career_decis=. if career_decis==0
label define career_decis 1 "absolutely decided"  2 "very decided" 3 "decided" 4 "undecided" 5 "very undecided"
label values career_decis career_decis
inspect career_decis
describe career_decis

/* variable: career_decishow */
rename p33 career_decishow
replace career_decishow=. if career_decishow==0
label define career_decishow 1 "conversation with colleagues"  2 "information in media" 3 "family influence" 4 "teachers' influence" 5 "other reason"
label values career_decishow career_decishow
inspect career_decishow
describe career_decishow

/* variable: income_cat */
rename p34 income_cat
replace income_cat=. if income_cat==0
label define income_cat 1 "up to 1 min wage"  2 "1-3 min wage" 3 "3-5 min wage" 4 "5-10 min wage" 5 "10-15 min wage" 6 "15-20 min wage" 7 "20-30 min wage" 8 "30-40 min wage" 9 "more than 40 min wage"
label values income_cat income_cat
inspect income_cat
describe income_cat

label define member_num 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6+"

/* variable: member_live */
rename p35 member_live
replace member_live=. if member_live==0
label values member_live member_num
inspect member_live
describe member_live

/* no other option in 2002 */
label define profes 1 "high politics, business, owner large company" 2 "self-employed, manager, owner medium company" 3 "supervision or inspection of non manual activities, owner small company" 4 "non-manual repetitive occupation" 5 "supervision manual occupation" 6 "specialized manual occupation" 7 "non-specialized manual occupation" 8 "house husband/wife" 9 "other"

/* variable: profes_father */
rename p36 profes_father
replace profes_father=. if profes_father==0
label values profes_father profes
inspect profes_father
describe profes_father

/* variable: situat_father */
rename p37 situat_father
replace situat_father=. if situat_father==0
label define situat_father 1 "company partner or owner" 2 "self-employed" 3 "private company employee" 4 "public employee" 5 "other situation"
label values situat_father situat_father
inspect situat_father
describe situat_father

/* variable: profes_mother */
rename p38 profes_mother
replace profes_mother=. if profes_mother==0
label values profes_mother profes
inspect profes_mother
describe profes_mother

/* variable: situat_mother */
rename p39 situat_mother
replace situat_mother=. if situat_mother==0
label define situat_mother 1 "company partner or owner" 2 "self-employed" 3 "private company employee" 4 "public employee" 5 "housewife" 6 "other situation"
label values situat_mother situat_mother
inspect situat_mother
describe situat_mother

label define educ 1 "no school" 2 "primary incomplete" 3 "primary complete" 4 "low secondary incomplete" 5 "low secondary complete" 6 "high secondary incomplete" 7 "high secondary complete" 8 "university incomplete" 9 "university complete"

/* variable: educ_father */
rename p40 educ_father
replace educ_father=. if educ_father==0
label values educ_father educ
inspect educ_father
describe educ_father

/* variable: educ_mother */
rename p41 educ_mother
replace educ_mother=. if educ_mother==0
label values educ_mother educ
inspect educ_mother
describe educ_mother

/* variable: working */
rename p42 working
replace working=. if working==0
label define working 1 "no" 2 "yes, occasionally" 3 "yes, half time (up to 20h)" 4 "yes, semi integral (21h-32h)" 5 "yes, integral (more than 32h)"
label values working working
inspect working
describe working

/* variable: econ_partic */
rename p43 econ_partic
replace econ_partic=. if econ_partic==0
label define econ_partic 1 "do no work, financed by family or other" 2 "work, but also financed by family" 3 "work, finance myself" 4 "work, finance myself and help family" 5 "work, finance my family"
label values econ_partic econ_partic
inspect econ_partic
describe econ_partic

/* variable: extra_activ */
rename p44 extra_activ
replace extra_activ=. if extra_activ==0
label define extra_activ 1 "artistical and cultural" 2 "religious" 3 "political" 4 "sporting" 5 "esoterical" 6 "other" 7 "none"
label values extra_activ extra_activ
inspect extra_activ
describe extra_activ

/* variable: other_activ */
rename p45 other_activ
replace other_activ=. if other_activ==0
label define other_activ 1 "watch tv" 2 "theater or cinema" 3 "music" 4 "bar or disco" 5 "reading" 6 "sport" 7 "internet" 8 "none"
label values other_activ other_activ
inspect other_activ
describe other_activ

/* variable: news_media */
rename p46 news_media
replace news_media=. if news_media==0
label define news_media 1 "newspaper" 2 "tv news" 3 "radio news" 4 "magazine" 5 "other people" 6 "no news"
label values news_media news_media
inspect news_media
describe news_media

/* variable: read_type */
rename p47 read_typew
recode read_typew (2=3) (3=1) (4=1) (5=4) (6=2) (7=2) (8=5), gen(read_type)
replace read_type=. if read_type==0
label define read_type 1 "fiction" 2 "non-fiction" 3 "poetry" 4 "other" 5 "none"
label values read_type read_type
drop read_typew
inspect read_type
describe read_type

/* variable: read_newspaper */
rename p48 read_newspaper
replace read_newspaper=. if read_newspaper==0
label define read_newspaper 1 "no" 2 "yes, occasionally" 3 "yes, on sundays" 4 "yes, daily"
label values read_newspaper read_newspaper
inspect read_newspaper
describe read_newspaper

/* variable: languages */
rename p49 languages
replace languages=. if languages==0
label define languages 1 "one or more very well" 2 "one or more well" 3 "one or more minimum"
label values languages languages
inspect languages
describe languages

/* variable: home_comp */
rename p50 home_comp
replace home_comp=. if home_comp==0
replace home_comp=0 if home_comp==2
label values home_comp yn
inspect home_comp
describe home_comp

sort inscription
merge 1:1 inscription using "Work data/QSEPR/V2003_QSEPR.dta"

compare career_choice	career_choice_pr                         
compare age       		age_pr                         
compare sex    			sex_pr   
compare race			race_pr                                  
compare sch_fund 		sch_fund_pr                         
compare sch_med  		sch_med_pr                        
compare type_med  		type_med_pr                        
compare prep_course 	prep_course_pr
compare type_prep_pr 	type_prep                                             
compare reason_unicamp  reason_unicamp_pr                        
compare reason_career 	reason_career_pr                         
compare income_cat  	income_cat_pr                                                     
compare member_live  	member_live_pr                        
compare profes_father 	profes_father_pr                         
compare profes_mother  	profes_mother_pr                        
compare educ_father 	educ_father_pr                         
compare educ_mother 	educ_mother_pr                         
compare working   		working_pr                       
compare read_newspaper  read_newspaper_pr

rename income_pr  income 			 
drop career_choice_pr age_pr sex_pr race_pr sch_fund_pr sch_med_pr type_med_pr prep_course_pr type_prep_pr reason_unicamp_pr reason_career_pr income_cat_pr member_live_pr profes_father_pr profes_mother_pr educ_father_pr educ_mother_pr working_pr read_newspaper_pr
drop _merge

append using "Work data/work_data_SE.dta"
compress
save "Work data/work_data_SE.dta", replace
clear

/* 2004 */

clear
insheet using "Original data/V2004_QSETT.txt"

describe

*********************************
*							    *
* VARIABLE: LABELS AND ANALYSIS *
*								*
*********************************

rename inscri inscription

gen year=2004
order year, after(inscription)

/* variable: sex */
rename p1 sex
replace sex=. if sex==0
label define sex 1 m 2 f
label values sex sex
inspect sex
describe sex

/* variable: age */
rename p2 age
replace age=. if age==0
label define age 1 "less than 16 years old" 2 "16 years old" 3 "17 years old" 4 "18 years old" 5 "19 years old" 6 "20 years old" 7 "21-23 years old" 8 "24-29 years old" 9 "more than 29 years old"
label values age age
inspect age
describe age

/* variable: marstat */
rename p3 marstat
replace marstat=. if marstat==0
label define marstat 1 single 2 married 3 widowed 4 divorced 5 other
label values marstat marstat
inspect marstat
describe marstat

/* variable: race */
rename p4 race
replace race=. if race==0
label define race 1 white 2 black 3 mulatto 4 asian 5 native
label values race race
inspect race
describe race

/* variable: resid_fam_or */
/* this variable is not compatible with other years */
gen resid_fam_orw=p5
replace resid_fam_orw=. if resid_fam_orw==0
recode resid_fam_orw (2=7) (3=8) (4=9) (5=10), gen(resid_fam_or)
label define resid_fam_or 1 "sao paulo metropolitan region" 2 "sao paulo inland" 3 "sao paulo coast" 4 "other state capital" 5 "other state inland" 6 "other state coast" 7 "campinas metropolitan region" 8 "santos metropolitan region" 9 "other regions sao paulo state" 10 "other state"
label values resid_fam_or resid_fam_or
drop resid_fam_orw
inspect resid_fam_or
describe resid_fam_or

/* variable: resid_fam */
/* group to be compatible with 2003 recode */
rename p5 resid_famw
recode resid_famw (3=2) (4=2) (5=3), gen(resid_fam)
replace resid_fam=. if resid_fam==0
label define resid_fam 1 "sao paulo metropolitan region" 2 "other region sao paulo state" 3 "other state"
label values resid_fam resid_fam
drop resid_famw
inspect resid_fam
describe resid_fam

/* variable: other_vest */
rename p6 other_vest
replace other_vest=. if other_vest==0
label define other_vest 1 "only unicamp" 2 "unicamp and fuvest" 3 "unicamp and vunesp" 4 "unicamp, fuvest and vunesp" 5 "unicamp and other private" 6 "unicamp and other public" 7 "unicamp and other public and private" 8 "other"
label values other_vest other_vest
inspect other_vest
describe other_vest

/* create a label for sch_fund and sch_med */
label define sch 1 onlypriv 2 onlypub 3 pubpriv 4 privpub 5 half 6 none

/* variable: sch_fund */
rename p7 sch_fund
replace sch_fund=. if sch_fund==0
label values sch_fund sch
inspect sch_fund
describe sch_fund

/* variable: sch_med */
rename p8 sch_med
replace sch_med=. if sch_med==0
label values sch_med sch
inspect sch_med
describe sch_med

/* variable: type_med */
/* recode to be compatible with 2003 (no regularprep) */
rename p9 type_medw
recode type_medw (4=3) (5=4) (6=5) (7=6), gen(type_med)
replace type_med=. if type_med==0
label define type_med 1 technical 2 "teacher training" 3 regular 4 accelerated  5 abroad 6 other
label values type_med type_med
drop type_medw
inspect type_med
describe type_med

/* variable: type_tech */
rename p10 type_tech
replace type_tech=. if type_tech==0
label define type_tech 1 "related to a public university, federal or state center" 2 "related to an institution" 3 "private" 4 "magisterio"  5 "other"
label values type_tech type_tech
inspect type_tech
describe type_tech

/* variable: period_med */
rename p11 period_med
replace period_med=. if period_med==0
label define period_med 1 morning 2 afternoon 3 evening 4 morneven 5 evenmorn 6 wholeday 7 other
label values period_med period_med
inspect period_med
describe period_med

/* variable: repeat_med */
rename p12 repeat_med
replace repeat_med=. if repeat_med==0
label define repeat_med 1 "no" 2 "yes, once" 3 "yes, twice" 4 "yes, 3 times" 5 "yes, more than 3 times"
label values repeat_med repeat_med
inspect repeat_med
describe repeat_med

/* create a label for yes and no questions */
label define yn 2 "not-appl" 1 yes 0 no

/* variable: prep_course */
rename p13 prep_course
replace prep_course=. if prep_course==0
replace prep_course=0 if prep_course==2
label values prep_course yn
inspect prep_course
describe prep_course

/* variable: reason_prep */
rename p14 reason_prep
replace reason_prep=. if reason_prep==0
label define reason_prep 1 "school does not prepare well" 2 "reinforce school" 3 "stop study long time ago" 4 "integrated at school" 5 "scholarship" 6 "other"
label values reason_prep reason_prep
inspect reason_prep
describe reason_prep

/* variable: durat_prep */
rename p15 durat_prep
replace durat_prep=. if durat_prep==0
label define durat_prep 1 "< 6 months" 2 "6 months-1 year" 3 "up to 1.5year" 4 "up to 2 years" 5 "more than 2 years"
label values durat_prep durat_prep
inspect durat_prep
describe durat_prep

/* variable: type_prep */
rename p16 type_prep
replace type_prep=. if type_prep==0
label define type_prep 1 commercial 2 community 
label values type_prep type_prep
inspect type_prep
describe type_prep

/* variable: scholars_prep */
rename p17 scholars_prep
replace scholars_prep=. if scholars_prep==0
label define scholars_prep 1 "yes, merit" 2 "yes, economic" 3 "yes, other" 4 "no"
label values scholars_prep scholars_prep
inspect scholars_prep
describe scholars_prep

/* variable: period_prep */
rename p18 period_prep
replace period_prep=. if period_prep==0
label define period_prep 1 "morning" 2 "afternoon" 3 "evening" 4 "other"
label values period_prep period_prep
inspect period_prep
describe period_prep

/* variable: reason_noprep */
rename p19 reason_noprep
replace reason_noprep=. if reason_noprep==0
label define reason_noprep 1 "school prepares well" 2 "economic difficulties" 3 "coincide with work time" 4 "thought could study alone" 5 "no prep close to home" 6 "school offers integrated" 7 "other"
label values reason_noprep reason_noprep
inspect reason_noprep
describe reason_noprep

/* variable: vest_before */
rename p20 vest_before
replace vest_before=. if vest_before==0
label define vest_before 1 "no" 2 "yes, one" 3 "yes, twice" 4 "yes, three" 5 "yes, more than three"
label values vest_before vest_before
inspect vest_before
describe vest_before

/* variable: vest_beforwhere */
rename p21 vest_beforwhere
replace vest_beforwhere=. if vest_beforwhere==0
label define vest_beforwhere 1 "only unicamp" 2 "unicamp and other public" 3 "only other public" 4 "unicamp and private" 5 "only private" 6 "unicamp and other public and private" 7 "only other public and private"
label values vest_beforwhere vest_beforwhere
inspect vest_beforwhere
describe vest_beforwhere

/* variable: other_univ */
rename p22 other_univ
replace other_univ=. if other_univ==0
replace other_univ=0 if other_univ==2
label values other_univ yn
inspect other_univ
describe other_univ

/* variable: other_univreas */
rename p23 other_univreas
replace other_univreas=. if other_univreas==0
label define other_univreas 1 "dropped out" 2 "over" 3 "will give up" 4 "do both" 5 "keep other, only experience vestibular" 6 "other"
label values other_univreas other_univreas
inspect  other_univreas
describe other_univreas

/* variable: reason_unicamp */
rename p24 reason_unicamp
replace reason_unicamp=. if reason_unicamp==0
label define reason_unicamp 1 "best for the course"  2 "free" 3 "close to residence" 4 "friends" 5 "reputation" 6 "rich cultural university life" 7 "access to scientific career" 8 "other"
label values reason_unicamp reason_unicamp
inspect reason_unicamp
describe reason_unicamp

/* variable: reason_career */
rename p25 reason_career
replace reason_career=. if reason_career==0
label define reason_career 1 "personal ability"  2 "social status" 3 "jobmarket" 4 "contribution to society" 5 "low competition for access" 6 "personal realization" 7 "other"
label values reason_career reason_career
inspect reason_career
describe reason_career

/* variable: career_decis */
rename p26 career_decis
replace career_decis=. if career_decis==0
label define career_decis 1 "absolutely decided"  2 "very decided" 3 "decided" 4 "undecided" 5 "very undecided"
label values career_decis career_decis
inspect career_decis
describe career_decis

/* variable: income_cat */
rename p27 income_cat
replace income_cat=. if income_cat==0
label define income_cat 1 "up to 1 min wage"  2 "1-3 min wage" 3 "3-5 min wage" 4 "5-10 min wage" 5 "10-15 min wage" 6 "15-20 min wage" 7 "20-30 min wage" 8 "30-40 min wage" 9 "more than 40 min wage"
label values income_cat income_cat
inspect income_cat
describe income_cat

label define member_num 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6+"

/* variable: member_live */
rename p28 member_live
replace member_live=. if member_live==0
label values member_live member_num
inspect member_live
describe member_live

/* variable: member_contr */
rename p29 member_contr
replace member_contr=. if member_contr==0
label values member_contr member_num
inspect member_contr
describe member_contr

/* variable: housing */
rename p30 housing
replace housing=. if housing==0
label define housing 1 "owned and paid" 2 "owned and not paid yet" 3 "rented" 4 "given" 5 "other"
label values housing housing
inspect housing
describe housing

label define profes 1 "high politics, business, owner large company" 2 "self-employed, manager, owner medium company" 3 "supervision or inspection of non manual activities, owner small company" 4 "non-manual repetitive occupation" 5 "supervision manual occupation" 6 "specialized manual occupation" 7 "non-specialized manual occupation" 8 "house husband/wife" 9 "other"

/* variable: profes_father */
rename p31 profes_father
replace profes_father=. if profes_father==0
label values profes_father profes
inspect profes_father
describe profes_father

/* variable: situat_father */
rename p32 situat_father
replace situat_father=. if situat_father==0
label define situat_father 1 "company partner or owner" 2 "self-employed" 3 "private company employee" 4 "public employee" 5 "other situation"
label values situat_father situat_father
inspect situat_father
describe situat_father

/* variable: profes_mother */
rename p33 profes_mother
replace profes_mother=. if profes_mother==0
label values profes_mother profes
inspect profes_mother
describe profes_mother

/* variable: situat_mother */
rename p34 situat_mother
replace situat_mother=. if situat_mother==0
label define situat_mother 1 "company partner or owner" 2 "self-employed" 3 "private company employee" 4 "public employee" 5 "housewife" 6 "other situation"
label values situat_mother situat_mother
inspect situat_mother
describe situat_mother

label define educ 1 "no school" 2 "primary incomplete" 3 "primary complete" 4 "low secondary incomplete" 5 "low secondary complete" 6 "high secondary incomplete" 7 "high secondary complete" 8 "university incomplete" 9 "university complete"

/* variable: educ_father */
rename p35 educ_father
replace educ_father=. if educ_father==0
label values educ_father educ
inspect educ_father
describe educ_father

/* variable: educ_mother */
rename p36 educ_mother
replace educ_mother=. if educ_mother==0
label values educ_mother educ
inspect educ_mother
describe educ_mother

/* variable: working */
rename p37 working
replace working=. if working==0
label define working 1 "no" 2 "yes, occasionally" 3 "yes, half time (up to 20h)" 4 "yes, semi integral (21h-32h)" 5 "yes, integral (more than 32h)"
label values working working
inspect working
describe working

/* variable: econ_partic */
rename p38 econ_partic
replace econ_partic=. if econ_partic==0
label define econ_partic 1 "do no work, financed by family or other" 2 "work, but also financed by family" 3 "work, finance myself" 4 "work, finance myself and help family" 5 "work, finance my family"
label values econ_partic econ_partic
inspect econ_partic
describe econ_partic

/* variable: financ_univ */
rename p39 financ_univ
replace financ_univ=. if financ_univ==0
label define financ_univ 1 "parents" 2 "work, but mainly parents" 3 "work and help parents" 4 "work" 5 "scholarship or educational credit" 6 "scholarship, educational credit, work and parents" 7 "other"
label values financ_univ financ_univ
inspect financ_univ
describe financ_univ

/* variable: extra_activ */
rename p40 extra_activ
replace extra_activ=. if extra_activ==0
label define extra_activ 1 "artistical and cultural" 2 "religious" 3 "political" 4 "sporting" 5 "esoterical" 6 "other" 7 "none"
label values extra_activ extra_activ
inspect extra_activ
describe extra_activ

/* variable: other_activ */
rename p41 other_activ
replace other_activ=. if other_activ==0
label define other_activ 1 "watch tv" 2 "theater or cinema" 3 "music" 4 "bar or disco" 5 "reading" 6 "sport" 7 "internet" 8 "none"
label values other_activ other_activ
inspect other_activ
describe other_activ

/* variable: news_media */
rename p42 news_media
replace news_media=. if news_media==0
label define news_media 1 "newspaper" 2 "tv news" 3 "radio news" 4 "magazine" 5 "other people" 6 "no news"
label values news_media news_media
inspect news_media
describe news_media

/* variable: read_type */
rename p43 read_typew
recode read_typew (2=3) (3=1) (4=1) (5=4) (6=2) (7=2) (8=5), gen(read_type)
replace read_type=. if read_type==0
label define read_type 1 "fiction" 2 "non-fiction" 3 "poetry" 4 "other" 5 "none"
label values read_type read_type
drop read_typew
inspect read_type
describe read_type

/* variable: read_newspaper */
rename p44 read_newspaper
replace read_newspaper=. if read_newspaper==0
label define read_newspaper 1 "no" 2 "yes, occasionally" 3 "yes, on sundays" 4 "yes, daily"
label values read_newspaper read_newspaper
inspect read_newspaper
describe read_newspaper

/* variable: home_books */
rename p45 home_books
replace home_books=. if home_books==0
label define home_books 1 "none" 2 "1-20 books" 3 "21-100 books" 4 "101+"
label values home_books home_books
inspect home_books
describe home_books

/* variable: home_calm */
rename p46 home_calm
replace home_calm=. if home_calm==0
replace home_calm=0 if home_calm==2
label values home_calm yn
inspect home_calm
describe home_calm

/* variable: membersh_newspaper */
rename p47 membersh_newspaper
replace membersh_newspaper=. if membersh_newspaper==0
replace membersh_newspaper=0 if membersh_newspaper==2
label values membersh_newspaper yn
inspect membersh_newspaper
describe membersh_newspaper

/* variable: membersh_magazine */
rename p48 membersh_magazine
replace membersh_magazine=. if membersh_magazine==0
replace membersh_magazine=0 if membersh_magazine==2
label values membersh_magazine yn
inspect membersh_magazine
describe membersh_magazine

/* variable: home_encicl */
rename p49 home_encicl
replace home_encicl=. if home_encicl==0
replace home_encicl=0 if home_encicl==2
label values home_encicl yn
inspect home_encicl
describe home_encicl

/* variable: home_atlas */
rename p50 home_atlas
replace home_atlas=. if home_atlas==0
replace home_atlas=0 if home_atlas==2
label values home_atlas yn
inspect home_atlas
describe home_atlas

/* variable: home_diccio */
rename p51 home_diccio
replace home_diccio=. if home_diccio==0
replace home_diccio=0 if home_diccio==2
label values home_diccio yn
inspect home_diccio
describe home_diccio

/* variable: home_calcul */
rename p52 home_calcul
replace home_calcul=. if home_calcul==0
replace home_calcul=0 if home_calcul==2
label values home_calcul yn
inspect home_calcul
describe home_calcul

/* variable: home_maid */
rename p53 home_maid
replace home_maid=. if home_maid==0
label define home_maid 1 "no" 2 "one, every day" 3 "two or more, every day" 4 "cleaning lady, once or twice a week"
label values home_maid home_maid
inspect home_maid
describe home_maid

/* variable: home_internet */
rename p54 home_internet
replace home_internet=. if home_internet==0
replace home_internet=0 if home_internet==2
label values home_internet yn
inspect home_internet
describe home_internet

label define home 1 "1" 2 "2" 3 "3" 4 "4+" 5 "none"

/* variable: home_kitch */
rename p55 home_kitchw
recode home_kitchw (1=5) (2=1) (3=2) (4=3) (5=4), gen(home_kitch)
replace home_kitch=. if home_kitch==0
label values home_kitch home
drop home_kitchw
inspect home_kitch
describe home_kitch

/* variable: home_livrooms */
rename p56 home_livroomsw
recode home_livroomsw (1=5) (2=1) (3=2) (4=3) (5=4), gen(home_livrooms)
replace home_livrooms=. if home_livrooms==0
label values home_livrooms home
drop home_livroomsw
inspect home_livrooms
describe home_livrooms

/* variable: home_bedr */
rename p57 home_bedrw
recode home_bedrw (1=5) (2=1) (3=2) (4=3) (5=4), gen(home_bedr)
replace home_bedr=. if home_bedr==0
label values home_bedr home
drop home_bedrw
inspect home_bedr
describe home_bedr

/* variable: home_bath */
rename p58 home_bathw
recode home_bathw (1=5) (2=1) (3=2) (4=3) (5=4), gen(home_bath)
replace home_bath=. if home_bath==0
label values home_bath home
drop home_bathw
inspect home_bath
describe home_bath

/* variable: home_radio */
rename p59 home_radiow
recode home_radiow (1=5) (2=1) (3=2) (4=3) (5=4), gen(home_radio)
replace home_radio=. if home_radio==0
label values home_radio home
drop home_radiow
inspect home_radio
describe home_radio

/* variable: home_tv */
rename p60 home_tvw
recode home_tvw (1=5) (2=1) (3=2) (4=3) (5=4), gen(home_tv)
replace home_tv=. if home_tv==0
label values home_tv home
drop home_tvw
inspect home_tv
describe home_tv

/* variable: home_vhs */
rename p61 home_vhsw
recode home_vhsw (1=5) (2=1) (3=2) (4=3) (5=4), gen(home_vhs)
replace home_vhs=. if home_vhs==0
label values home_vhs home
drop home_vhsw
inspect home_vhs
describe home_vhs

/* variable: home_refrig */
/* recode this variable to yes or no to be compatible with subsequent years */
rename p62 home_refrigw
replace home_refrig=. if home_refrig==0
recode home_refrigw (1=0) (2=1) (3=1) (4=1) (5=1), gen(home_refrig)
label values home_refrig yn
drop home_refrigw
inspect home_refrig
describe home_refrig

/* variable: home_freezer */
/* recode this variable to yes or no to be compatible with subsequent years */
rename p63 home_freezerw
replace home_freezer=. if home_freezer==0
recode home_freezerw (1=0) (2=1) (3=1) (4=1) (5=1), gen(home_freezer)
label values home_freezer yn
drop home_freezerw
inspect home_freezer
describe home_freezer

/* variable: home_washmach */
/* recode this variable to yes or no to be compatible with subsequent years */
rename p64 home_washmachw
replace home_washmach=. if home_washmach==0
recode home_washmachw (1=0) (2=1) (3=1) (4=1) (5=1), gen(home_washmach)
label values home_washmach yn
drop home_washmachw
inspect home_washmach
describe home_washmach

/* variable: home_vacuum */
/* recode this variable to yes or no to be compatible with subsequent years */
rename p65 home_vacuumw
replace home_vacuum=. if home_vacuum==0
recode home_vacuumw (1=0) (2=1) (3=1) (4=1) (5=1), gen(home_vacuum)
label values home_vacuum yn
drop home_vacuumw
inspect home_vacuum
describe home_vacuum

/* variable: home_comp */
/* recode to be compatible with 2003 */
rename p66 home_compw
replace home_comp=. if home_comp==0
recode home_compw (1=0) (2=1) (3=1) (4=1) (5=1), gen(home_comp)
label values home_comp yn
drop home_compw
inspect home_comp
describe home_comp

/* variable: home_cars */
rename p67 home_carsw
recode home_carsw (1=5) (2=1) (3=2) (4=3) (5=4), gen(home_cars)
replace home_cars=. if home_cars==0
label values home_cars home
drop home_carsw
inspect home_cars
describe home_cars

sort inscription
merge 1:1 inscription using "Work data/QSEPR/V2004_QSEPR.dta"
                       
compare age       		age_pr                         
compare sex    			sex_pr   
compare race			race_pr                                  
compare sch_fund 		sch_fund_pr                         
compare sch_med  		sch_med_pr                        
compare type_med  		type_med_pr                        
compare prep_course 	prep_course_pr
compare type_prep_pr 	type_prep                                             
compare reason_unicamp  reason_unicamp_pr                        
compare reason_career 	reason_career_pr                         
compare income_cat  	income_cat_pr                                                     
compare member_live  	member_live_pr                        
compare profes_father 	profes_father_pr                         
compare profes_mother  	profes_mother_pr                        
compare educ_father 	educ_father_pr                         
compare educ_mother 	educ_mother_pr                         
compare working   		working_pr                       
compare read_newspaper  read_newspaper_pr

rename income_pr  income
rename career_choice_pr career_choice	   			 
drop age_pr sex_pr race_pr sch_fund_pr sch_med_pr type_med_pr prep_course_pr type_prep_pr reason_unicamp_pr reason_career_pr income_cat_pr member_live_pr profes_father_pr profes_mother_pr educ_father_pr educ_mother_pr working_pr read_newspaper_pr
drop _merge

append using "Work data/work_data_SE.dta"
compress
save "Work data/work_data_SE.dta", replace
clear


/* 2005, 2006, 2007 and 2008 */
/* Some adaptations are performed using command capture noisily */

forvalues j = 5(1)8 {
clear
insheet using "Original data/V200`j'_QSETT.txt"

describe

*********************************
*							    *
* VARIABLE: LABELS AND ANALYSIS *
*								*
*********************************

rename inscri inscription
/* in 2008, age is a continuous variable, so create variable age2 */
capture noisily rename idade age2

gen year=200`j'
order year, after(inscription)

/* variable: sex */
rename sexo sex
replace sex=. if sex==0
label define sex 1 m 2 f
label values sex sex
inspect sex
describe sex

/* variable: marstat */
rename estcivil marstat
replace marstat=. if marstat==0
label define marstat 1 single 2 married 3 widowed 4 divorced 5 other
label values marstat marstat
inspect marstat
describe marstat

/* variable: race */
rename p1 race
replace race=. if race==0
label define race 1 white 2 black 3 mulatto 4 asian 5 native
label values race race
inspect race
describe race

/* create a label for sch_fund and sch_med */
label define sch 1 onlypriv 2 onlypub 3 pubpriv 4 privpub 5 half 6 none

/* variable: sch_fund */
rename p2 sch_fund
replace sch_fund=. if sch_fund==0
label values sch_fund sch
inspect sch_fund
describe sch_fund

/* variable: sch_med */
rename p3 sch_med
replace sch_med=. if sch_med==0
label values sch_med sch
inspect sch_med
describe sch_med

/* variable: type_med */
/* recode to be compatible with 2003 (no regularprep) */
rename p4 type_medw
recode type_medw (4=3) (5=4) (6=5) (7=6), gen(type_med)
replace type_med=. if type_med==0
label define type_med 1 technical 2 "teacher training" 3 regular 4 accelerated  5 abroad 6 other
label values type_med type_med
drop type_medw
inspect type_med
describe type_med

/* variable: period_med */
rename p5 period_med
replace period_med=. if period_med==0
label define period_med 1 morning 2 afternoon 3 evening 4 morneven 5 evenmorn 6 wholeday 7 other
label values period_med period_med
inspect period_med
describe period_med

/* create a label for yes and no questions */
label define yn 2 "not-appl" 1 yes 0 no

/* variable: prep_course */
rename p6 prep_course
replace prep_course=. if prep_course==0
replace prep_course=0 if prep_course==2
label values prep_course yn
inspect prep_course
describe prep_course

/* variable: reason_prep */
rename p7 reason_prep
replace reason_prep=. if reason_prep==0
label define reason_prep 1 "school does not prepare well" 2 "reinforce school" 3 "stop study long time ago" 4 "integrated at school" 5 "scholarship" 6 "other"
label values reason_prep reason_prep
inspect reason_prep
describe reason_prep

/* variable: durat_prep */
rename p8 durat_prep
replace durat_prep=. if durat_prep==0
label define durat_prep 1 "< 6 months" 2 "6 months-1 year" 3 "up to 1.5year" 4 "up to 2 years" 5 "more than 2 years"
label values durat_prep durat_prep
inspect durat_prep
describe durat_prep

/* variable: type_prep */
rename p9 type_prep
replace type_prep=. if type_prep==0
label define type_prep 1 commercial 2 community 
label values type_prep type_prep
inspect type_prep
describe type_prep

/* variable: other_univ */
rename p10 other_univ
replace other_univ=. if other_univ==0
replace other_univ=0 if other_univ==2
label values other_univ yn
inspect other_univ
describe other_univ

/* variable: reason_unicamp */
rename p11 reason_unicamp
replace reason_unicamp=. if reason_unicamp==0
label define reason_unicamp 1 "best for the course"  2 "free" 3 "close to residence" 4 "friends" 5 "reputation" 6 "rich cultural university life" 7 "access to scientific career" 8 "other"
label values reason_unicamp reason_unicamp
inspect reason_unicamp
describe reason_unicamp

/* variable: reason_career */
rename p12 reason_career
replace reason_career=. if reason_career==0
label define reason_career 1 "personal ability"  2 "social status" 3 "jobmarket" 4 "contribution to society" 5 "low competition for access" 6 "personal realization" 7 "other"
label values reason_career reason_career
inspect reason_career
describe reason_career

label define member_num 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6+"

/* variable: member_live */
rename p14 member_live
destring member_live, replace force
replace member_live=. if member_live==0
replace member_live=6 if member_live>6 & member_live<.
label values member_live member_num
inspect member_live
describe member_live

/* variable: member_contr */
rename p15 member_contr
destring member_contr, replace force
replace member_contr=. if member_contr==0
replace member_contr=6 if member_contr>6 & member_contr<.
label values member_contr member_num
inspect member_contr
describe member_contr

/* variable: housing */
rename p16 housing
replace housing=. if housing==0
label define housing 1 "owned and paid" 2 "owned and not paid yet" 3 "rented" 4 "given" 5 "other"
label values housing housing
inspect housing
describe housing

label define profes 1 "high politics, business, owner large company" 2 "self-employed, manager, owner medium company" 3 "supervision or inspection of non manual activities, owner small company" 4 "non-manual repetitive occupation" 5 "supervision manual occupation" 6 "specialized manual occupation" 7 "non-specialized manual occupation" 8 "house husband/wife" 9 "other"

/* variable: profes_father */
rename p17 profes_father
replace profes_father=. if profes_father==0
replace profes_father=9 if profes_father==10
label values profes_father profes
inspect profes_father
describe profes_father

/* variable: profes_mother */
rename p18 profes_mother
replace profes_mother=. if profes_mother==0
replace profes_mother=9 if profes_mother==10
label values profes_mother profes
inspect profes_mother
describe profes_mother

label define educ 1 "no school" 2 "primary incomplete" 3 "primary complete" 4 "low secondary incomplete" 5 "low secondary complete" 6 "high secondary incomplete" 7 "high secondary complete" 8 "university incomplete" 9 "university complete"

/* variable: educ_father */
/* recode to eliminate post university to be compatible with the years before 2005 */
rename p19 educ_fatherw
recode educ_fatherw (10=9) (11=9), gen(educ_father)
replace educ_father=. if educ_father==0
label values educ_father educ
drop educ_fatherw
inspect educ_father
describe educ_father

/* variable: educ_mother */
/* recode to eliminate post university to be compatible with the years before 2005 */
rename p20 educ_motherw
recode educ_motherw (10=9) (11=9), gen(educ_mother)
replace educ_mother=. if educ_mother==0
label values educ_mother educ
drop educ_motherw
inspect educ_mother
describe educ_mother

/* variable: working */
rename p21 working
replace working=. if working==0
label define working 1 "no" 2 "yes, occasionally" 3 "yes, half time (up to 20h)" 4 "yes, semi integral (21h-32h)" 5 "yes, integral (more than 32h)"
label values working working
inspect working
describe working

/* variable: econ_partic */
rename p22 econ_partic
replace econ_partic=. if econ_partic==0
label define econ_partic 1 "do no work, financed by family or other" 2 "work, but also financed by family" 3 "work, finance myself" 4 "work, finance myself and help family" 5 "work, finance my family"
label values econ_partic econ_partic
inspect econ_partic
describe econ_partic

/* variable: read_newspaper */
rename p23 read_newspaper
replace read_newspaper=. if read_newspaper==0
label define read_newspaper 1 "no" 2 "yes, occasionally" 3 "yes, on sundays" 4 "yes, daily"
label values read_newspaper read_newspaper
inspect read_newspaper
describe read_newspaper

/* variable: home_books */
rename p24 home_books
replace home_books=. if home_books==0
label define home_books 1 "none" 2 "1-20 books" 3 "21-100 books" 4 "101+"
label values home_books home_books
inspect home_books
describe home_books

/* variable: home_calm */
rename p25 home_calm
replace home_calm=. if home_calm==0
replace home_calm=0 if home_calm==2
label values home_calm yn
inspect home_calm
describe home_calm

/* variable: membersh_newspaper */
rename p26 membersh_newspaper
replace membersh_newspaper=. if membersh_newspaper==0
replace membersh_newspaper=0 if membersh_newspaper==2
label values membersh_newspaper yn
inspect membersh_newspaper
describe membersh_newspaper

/* variable: membersh_magazine */
rename p27 membersh_magazine
replace membersh_magazine=. if membersh_magazine==0
replace membersh_magazine=0 if membersh_magazine==2
label values membersh_magazine yn
inspect membersh_magazine
describe membersh_magazine

/* variable: home_encicl */
rename p28a home_encicl
replace home_encicl=. if home_encicl==0
replace home_encicl=0 if home_encicl==2
label values home_encicl yn
inspect home_encicl
describe home_encicl

/* variable: home_atlas */
rename p28b home_atlas
replace home_atlas=. if home_atlas==0
replace home_atlas=0 if home_atlas==2
label values home_atlas yn
inspect home_atlas
describe home_atlas

/* variable: home_diccio */
rename p28c home_diccio
replace home_diccio=. if home_diccio==0
replace home_diccio=0 if home_diccio==2
label values home_diccio yn
inspect home_diccio
describe home_diccio

/* variable: home_calcul */
rename p28d home_calcul
replace home_calcul=. if home_calcul==0
replace home_calcul=0 if home_calcul==2
label values home_calcul yn
inspect home_calcul
describe home_calcul

/* variable: home_maid */
rename p29 home_maid
replace home_maid=. if home_maid==0
label define home_maid 1 "no" 2 "one, every day" 3 "two or more, every day" 4 "cleaning lady, once or twice a week"
label values home_maid home_maid
inspect home_maid
describe home_maid

/* variable: home_internet */
rename p30 home_internet
replace home_internet=. if home_internet==0
replace home_internet=0 if home_internet==2
label values home_internet yn
inspect home_internet
describe home_internet

label define home 1 "1" 2 "2" 3 "3" 4 "4+" 5 "none"

/* variable: home_kitch */
rename p31a home_kitch
replace home_kitch=. if home_kitch==0
label values home_kitch home
inspect home_kitch
describe home_kitch

/* variable: home_livrooms */
rename p31b home_livrooms
replace home_livrooms=. if home_livrooms==0
label values home_livrooms home
inspect home_livrooms
describe home_livrooms

/* variable: home_bedr */
rename p31c home_bedr
replace home_bedr=. if home_bedr==0
label values home_bedr home
inspect home_bedr
describe home_bedr

/* variable: home_bath */
rename p31d home_bath
replace home_bath=. if home_bath==0
label values home_bath home
inspect home_bath
describe home_bath

/* variable: home_radio */
rename p32a home_radio
replace home_radio=. if home_radio==0
label values home_radio home
inspect home_radio
describe home_radio

/* variable: home_hifi */
rename p32b home_hifi
replace home_hifi=. if home_hifi==0
label values home_hifi home
inspect home_hifi
describe home_hifi

/* variable: home_tv */
rename p32c home_tv
replace home_tv=. if home_tv==0
label values home_tv home
inspect home_tv
describe home_tv

/* variable: home_vhs */
rename p32d home_vhs
replace home_vhs=. if home_vhs==0
label values home_vhs home
inspect home_vhs
describe home_vhs

/* variable: home_dvd */
rename p32e home_dvd
replace home_dvd=. if home_dvd==0
label values home_dvd home
inspect home_dvd
describe home_dvd

/* variable: home_comp */
/* recode to be compatible with 2003 */
rename p32f home_compw
replace home_comp=. if home_comp==0
recode home_compw (1=1) (2=1) (3=1) (4=1) (5=0), gen(home_comp)
label values home_comp yn
drop home_compw
inspect home_comp
describe home_comp

/* variable: home_cars */
rename p32g home_cars
replace home_cars=. if home_cars==0
label values home_cars home
inspect home_cars
describe home_cars

/* variable: home_refrig */
rename p33a home_refrig
replace home_refrig=. if home_refrig==0
replace home_refrig=0 if home_refrig==2
label values home_refrig yn
inspect home_refrig
describe home_refrig

/* variable: home_washmach */
rename p33b home_washmach
replace home_washmach=. if home_washmach==0
replace home_washmach=0 if home_washmach==2
label values home_washmach yn
inspect home_washmach
describe home_washmach

/* variable: home_vacuum */
rename p33c home_vacuum
replace home_vacuum=. if home_vacuum==0
replace home_vacuum=0 if home_vacuum==2
label values home_vacuum yn
inspect home_vacuum
describe home_vacuum

/* variable: home_freezer */
rename p33d home_freezer
replace home_freezer=. if home_freezer==0
replace home_freezer=0 if home_freezer==2
label values home_freezer yn
inspect home_freezer
describe home_freezer

/* variable: home_dishwash */
rename p33e home_dishwash
replace home_dishwash=. if home_dishwash==0
replace home_dishwash=0 if home_dishwash==2
label values home_dishwash yn
inspect home_dishwash
describe home_dishwash

/* variable: city_exam */
/* in 2005-2007, no city_inscri, but instead city_exam */
capture noisily rename cidprova city_exam
capture noisily describe city_exam

/* variable: city_inscri */
/* in 2008, no city_exam, but instead city_inscri */
capture noisily rename cidinscri city_inscri
capture noisily describe city_inscri

/* variable: income */
capture noisily rename renda income
capture noisily rename p13 income
replace income=. if income==0
inspect income
describe income
capture noisily drop p13

sort inscription
merge 1:1 inscription using "Work data/QSEPR/V200`j'_QSEPR.dta"

/* apply the same recoding to the variable on QSEPR */
replace member_live_pr=6 if member_live_pr>6 & member_live_pr<.
                        
compare sex    			sex_pr   
compare race			race_pr                                  
compare sch_fund 		sch_fund_pr                         
compare sch_med  		sch_med_pr                        
compare type_med  		type_med_pr                        
compare prep_course 	prep_course_pr
compare type_prep_pr 	type_prep                                             
compare reason_unicamp  reason_unicamp_pr                        
compare reason_career 	reason_career_pr                         
compare income			income_pr  	                                                   
compare member_live  	member_live_pr                        
compare profes_father 	profes_father_pr                         
compare profes_mother  	profes_mother_pr                        
compare educ_father 	educ_father_pr                         
compare educ_mother 	educ_mother_pr                         
compare working   		working_pr                       
compare read_newspaper  read_newspaper_pr

rename career_choice_pr career_choice	
rename age_pr age       
* The variable income_cat does not exist in QSETT for 2005-2008, so use the one in QSEPR.	
rename income_cat_pr income_cat			 
drop sex_pr race_pr sch_fund_pr sch_med_pr type_med_pr prep_course_pr type_prep_pr reason_unicamp_pr reason_career_pr income_pr member_live_pr profes_father_pr profes_mother_pr educ_father_pr educ_mother_pr working_pr read_newspaper_pr
drop _merge

append using "Work data/work_data_SE.dta"
format %13.0g studentno 
compress
save "Work data/work_data_SE.dta", replace
clear
}

use "Work data/work_data_SE.dta"
order studentno inscription year sex age age2 marstat race aa_policy regist_fee city_inscri city_exam career_choice group  pass_st1 enroll career_enroll
save "Work data/work_data_SE.dta", replace

sort studentno
merge 1:1 studentno using "Work data/treineiros.dta"
replace training=0 if _merge==1
drop _merge

* Generating Dummies for Applicant Characteristics

gen aa_year=(year>=2005)
gen aa_2005=(year==2005)
gen all_public=(sch_med==2) if !missing(sch_med)
gen vis_min= (race==2 | race==3 | race==5) if !missing(race)
gen minority_all_public=all_public*vis_min
gen vis_min_aa=vis_min*aa_year
gen all_public_aa=all_public*aa_year
gen minority_all_public_aa=minority_all_public*aa_year

gen female = (sex==2) if !missing(sex)
gen father_univ= (educ_father==9) if !missing(educ_father)
gen father_hs= (educ_father>6 & educ_father<9) if !missing(educ_father)
gen father_drop= (educ_father<7) if !missing(educ_father)

gen mother_univ=(educ_mother==9) if !missing(educ_mother)
gen mother_hs=(educ_mother>6 & educ_mother<9) if !missing(educ_mother)
gen mother_drop=(educ_mother<7) if !missing(educ_mother)
gen aged_under17=(age==1 | age==2) if !missing(age)
gen aged_17=(age==3) if !missing(age)
gen aged_18=(age==4) if !missing(age)
gen aged_19=(age==5) if !missing(age)
gen aged_20=(age==6) if !missing(age)
gen aged_over_20=(age>6) if !missing(age)
gen first_time=(vest_before==1) if !missing(vest_before)
gen only_unicamp=(other_vest==1) if !missing(other_vest)
gen applied_public=((other_vest>0 & other_vest<5) | other_vest==6) if !missing(other_vest)
gen undecided=(career_decis==4 | career_decis==5) if !missing(career_decis)
gen decided=(career_decis==1 | career_decis==2) if !missing(career_decis)
gen decided_2=(career_decis==1) if !missing(career_decis)

* Merge with the database that contains the municipalities and age and was created by "cities_states_age.do"

sort studentno
merge 1:1 studentno using "Work data/OptionsMunicAge.dta"
gen matched= (_merge==3)
drop if _merge==2
drop _merge

gen agejun2=agejun*agejun
gen agejun3=agejun*agejun2
gen agejun4=agejun*agejun3

replace career_choice=curso
replace career_choice=. if career_choice==0
replace curso2=. if curso2==0
replace curso3=. if curso3==0

replace career_enroll=curpas
replace career_enroll=0 if career_enroll==.

*Reorganizing music majors code and engineering
*Note: group variable is not available for 2000

foreach x in career_choice {
replace group=141 if year<2004 & (`x' == 2 | `x' == 8 | `x' == 10 |`x' == 12| `x' ==13 | `x' == 29| `x' == 34| `x' == 40| `x' == 42| `x' == 43| `x' == 49| `x' == 51)         
replace group=143 if year<2004 & (`x' == 11| `x' == 41)         
replace group=144 if year<2004 & (`x' == 9 | `x' == 39)
replace group=145 if year<2004 & (`x' == 31 | `x' == 62 | `x' == 36 | `x' == 37 | `x' == 60)
replace group=146 if year<2004 & (`x' == 5)
replace group=147 if year<2004 & (`x' == 50)
replace group=148 if year<2004 & (`x' == 52|  `x' == 55)
replace group=149 if year<2004 & (`x' == 48)
replace group=151 if year<2004 & (`x' == 7 |  `x' == 16 | `x' == 18| `x' == 19| `x' ==20|  `x' == 38|  `x' == 44|  `x' == 57)
replace group=152 if year<2004 & (`x' == 30)
replace group=153 if year<2004 & (`x' == 17|  `x' == 47)
replace group=154 if year<2004 & (`x' == 56)
replace group=161 if year<2004 & (`x' == 90)
replace group=162 if year<2004 & (`x' == 91)
replace group=163 if year<2004 & (`x' == 92)  
replace group=166 if year<2004 & (`x' == 23)
replace group=167 if year<2004 & (`x' == 25)
replace group=168 if year<2004 & (`x' == 26)
replace group=169 if year<2004 & (`x' == 93)
replace group=171 if year<2004 & (`x' == 6)
replace group=172 if year<2004 & (`x' == 14)
replace group=173 if year<2004 & (`x' == 15|  `x' == 75)
replace group=174 if year<2004 & (`x' == 21|  `x' == 81)
replace group=175 if year<2004 & (`x' == 27|  `x' == 45)
replace group=176 if year<2004 & (`x' == 58)
replace group=177 if year<2004 & (`x' == 46)
}

foreach x in  career_choice career_enroll {

replace `x' = 90 if `x' == 22 & group == 161 
replace `x' = 91 if `x' == 22 & group == 162 
replace `x' = 92 if `x' == 22 & group == 163 
replace `x' = 93 if `x' == 22 & group == 169 
replace `x' = 92 if `x' == 71 
replace `x' = 93 if `x' == 72 
replace `x' = 100 if `x' == 70 & year == 2004 
replace `x' = 90 if `x' == 70 & year != 2004
replace `x' = 91 if `x' == 88
replace `x' = 62 if `x' == 31
}

* Defining Popular Program Dummies
gen app_med_unicamp=(career_choice==15) if !missing(career_choice)
gen app_med_famerp=(career_choice==75) if !missing(career_choice)
gen app_comp_eng=(career_choice==34) if !missing(career_choice)
gen app_bio_sci=(career_choice==6) if !missing(career_choice)
gen app_mec_eng=(career_choice==10) if !missing(career_choice)
gen app_econ=(career_choice==17) if !missing(career_choice)
gen app_comp_sci=(career_choice==42) if !missing(career_choice)
gen app_auto_eng=(career_choice==49) if !missing(career_choice)
gen app_elec_eng=(career_choice==11) if !missing(career_choice)
gen app_dent=(career_choice==14) if !missing(career_choice)
gen app_nurse_unicamp=(career_choice==21) if !missing(career_choice)
gen app_nurse_famerp=(career_choice==81) if !missing(career_choice)

* Parents Occupation

* Note: There is no option for unemployed

gen fa_manual_occ=(profes_father==6 | profes_father==7) if !missing(profes_father)
* These are specialized and non-specialized manual occupations
gen fa_top_occ=(profes_father==1 | profes_father==2) if !missing(profes_father)
* This is "high politics, business, owner large co, self-employed, manager, owner medium co"
gen fa_medium_occ=(profes_father==3 | profes_father==4 | profes_father==5) if !missing(profes_father)
* This is "supervision occupations"
gen fa_other_occ=(profes_father==8 | profes_father==9) if !missing(profes_father)
* This are "other occupations, housewife/househusband"

gen mo_manual_occ=(profes_mother==6 | profes_mother==7) if !missing(profes_mother)
* These are specialized and non-specialized manual occupations
gen mo_top_occ=(profes_mother==1 | profes_mother==2) if !missing(profes_mother)
* This is "high politics, business, owner large co, self-employed, manager, owner medium co"
gen mo_medium_occ=(profes_mother==3 | profes_mother==4 | profes_mother==5) if !missing(profes_mother)
* This is "supervision occupations"
gen mo_other_occ=(profes_mother==8 | profes_mother==9) if !missing(profes_mother)
* This are "other occupations, housewife/househusband"

* Work and Study Finance
gen financed=(econ_partic==1 | econ_partic==2) if !missing(econ_partic)
gen help_family=(econ_partic==4 | econ_partic==5) if !missing(econ_partic)
gen work_32_plus=(working==5) if !missing(working)
gen no_work=(working==1) if !missing(working)

* Read Newspapers
gen newspaper_dayly=(read_newspaper==4) if !missing(read_newspaper)
gen newspaper_yn=(read_newspaper!=1) if !missing(read_newspaper)

save "Work data/work_data_SE.dta", replace
